Fix bug when switching sources

This commit is contained in:
Sam Potts 2017-08-06 13:42:37 +10:00
parent a9957211f4
commit f7144dc0cb
4 changed files with 14 additions and 24 deletions

2
demo/dist/demo.js vendored

File diff suppressed because one or more lines are too long

4
dist/plyr.js vendored

File diff suppressed because one or more lines are too long

View File

@ -343,7 +343,7 @@ Note the single quotes encapsulating the JSON and double quotes on the object ke
<td>This will restore and *reload* HTML5 video once playback is complete. Note: depending on the browser caching, this may result in the video downloading again (or parts of it). Use with caution.</td> <td>This will restore and *reload* HTML5 video once playback is complete. Note: depending on the browser caching, this may result in the video downloading again (or parts of it). Use with caution.</td>
</tr> </tr>
<tr> <tr>
<td><code>keyboardShortcuts</code></td> <td><code>keyboard</code></td>
<td>Object</td> <td>Object</td>
<td><code>{ focused: true, global: false }</code></td> <td><code>{ focused: true, global: false }</code></td>
<td>Enable <a href="#shortcuts">keyboard shortcuts</a> for focused players only or globally as well (this will only work if there's one player in the document)</td> <td>Enable <a href="#shortcuts">keyboard shortcuts</a> for focused players only or globally as well (this will only work if there's one player in the document)</td>

View File

@ -153,7 +153,7 @@
}, },
// Keyboard shortcut settings // Keyboard shortcut settings
keyboardShortcuts: { keyboard: {
focused: true, focused: true,
global: false global: false
}, },
@ -3439,9 +3439,6 @@
return; return;
} }
// Stop playback
player.stop();
// Update seek range and progress // Update seek range and progress
updateSeekDisplay(); updateSeekDisplay();
@ -3451,15 +3448,11 @@
// Cancel current network requests // Cancel current network requests
cancelRequests(); cancelRequests();
// Setup new source // Destroy instance and re-setup
function setup() { player.destroy(function() {
// Remove media // Remove elements
removeElement(player.media); removeElement(player.media);
// Remove the old captions
removeElement('captions'); removeElement('captions');
// Remove video container
removeElement('wrapper'); removeElement('wrapper');
// Reset class name // Reset class name
@ -3565,11 +3558,7 @@
// Set aria title and iframe title // Set aria title and iframe title
player.config.title = source.title; player.config.title = source.title;
setTitle(); setTitle();
} }, false);
// Destroy instance adn wait for callback
// Vimeo throws a wobbly if you don't wait
player.destroy(setup, false);
} }
// Listen for control events // Listen for control events
@ -3617,11 +3606,11 @@
} }
// Keyboard shortcuts // Keyboard shortcuts
if (player.config.keyboardShortcuts.focused) { if (player.config.keyboard.focused) {
var last = null; var last = null;
// Handle global presses // Handle global presses
if (player.config.keyboardShortcuts.global) { if (player.config.keyboard.global) {
utils.on(window, 'keydown keyup', function(event) { utils.on(window, 'keydown keyup', function(event) {
var code = getKeyCode(event); var code = getKeyCode(event);
var focused = utils.getFocusElement(); var focused = utils.getFocusElement();
@ -4458,14 +4447,15 @@
// Set the current time // Set the current time
// Embeds // Embeds
if (utils.inArray(types.embed, player.type)) { if (utils.inArray(types.embed, player.type)) {
console.warn(player.type, typeof player.embed, typeof player.embed.seekTo);
switch (player.type) { switch (player.type) {
case 'youtube': case 'youtube':
player.embed.seekTo(targetTime); player.embed.seekTo(targetTime);
break; break;
case 'vimeo': case 'vimeo':
// Round to nearest second for vimeo player.embed.setCurrentTime(targetTime);
player.embed.setCurrentTime(targetTime.toFixed(0));
break; break;
case 'soundcloud': case 'soundcloud':