Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop calling pause() before play promise resolved #68

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 38 additions & 11 deletions scripts/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,20 +414,31 @@ H5P.VideoHtml5 = (function ($) {
self.seek(currentTimeBeforeChangingQuality);
}

// Always play to get image.
video.play();
// Callback to resolve play
var resolvePlaying = function () {
if (stateBeforeChangingQuality !== H5P.Video.PLAYING) {
// Do not resume playing
video.pause();
}

if (stateBeforeChangingQuality !== H5P.Video.PLAYING) {
// Do not resume playing
video.pause();
}
// Done changing quality
stateBeforeChangingQuality = undefined;

// Done changing quality
stateBeforeChangingQuality = undefined;
// Remove any errors
if ($error.is(':visible')) {
$error.remove();
}
};

// Remove any errors
if ($error.is(':visible')) {
$error.remove();
// Always play to get image.
var playPromise = video.play();
if (playPromise !== undefined) {
playPromise.finally(() => {
resolvePlaying();
});
}
else {
resolvePlaying(); // Fallback
}
};
video.addEventListener('loadedmetadata', loaded, false);
Expand Down Expand Up @@ -489,6 +500,22 @@ H5P.VideoHtml5 = (function ($) {
* @param {Number} time
*/
self.seek = function (time) {
if (lastState === undefined) {
// Make sure we always play before we seek to get an image.
// If not iOS devices will reset currentTime when pressing play.

// Always play to get image.
var playPromise = video.play();
if (playPromise !== undefined) {
playPromise.finally(() => {
video.pause();
});
}
else {
video.pause(); // Fallback
}
}

video.currentTime = time;
// Use canplaythrough for IOs devices
// Use loadedmetadata for all other devices.
Expand Down