Skip to content

Commit

Permalink
[#3451] Properly play again if media with greater duration added whil…
Browse files Browse the repository at this point in the history
…e playing
  • Loading branch information
ScottDowne committed Apr 1, 2013
1 parent 7f83ec7 commit 50a9bd1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions public/src/editor/media-gallery-editor.js
Expand Up @@ -148,6 +148,7 @@ define( [ "util/lang", "util/xhr", "util/keys", "util/mediatypes", "editor/edito
function addEvent() {
var start = _butter.currentTime,
end = start + data.duration,
playWhenReady = false,
trackEvent;

function addTrackEvent() {
Expand All @@ -168,9 +169,13 @@ define( [ "util/lang", "util/xhr", "util/keys", "util/mediatypes", "editor/edito
if ( end > _media.duration ) {
_butter.listen( "mediaready", function onMediaReady() {
_butter.unlisten( "mediaready", onMediaReady );
if ( playWhenReady ) {
_media.play();
}
addTrackEvent();
});

playWhenReady = !_media.paused
setBaseDuration( end );
} else {
addTrackEvent();
Expand Down
6 changes: 6 additions & 0 deletions public/src/editor/sequencer-editor.js
Expand Up @@ -113,6 +113,7 @@ define( [ "util/mediatypes", "editor/editor", "util/time",
startLeft,
startWidth,
activeHandle,
playWhenReady = false,
updateOptions = {};

// Converting px <=> time, normalizing
Expand Down Expand Up @@ -162,6 +163,10 @@ define( [ "util/mediatypes", "editor/editor", "util/time",

function updateEndAfterExpand() {
var track = _trackEvent.track;
if ( playWhenReady ) {
playWhenReady = false;
_butter.currentMedia.play();
}
track.removeTrackEvent( _trackEvent );
track.addTrackEvent( _trackEvent );
_this.updateTrackEventSafe( _trackEvent, updateOptions );
Expand All @@ -175,6 +180,7 @@ define( [ "util/mediatypes", "editor/editor", "util/time",
// If the end time is greater than the duration of the video, expand it to fit.
// We have to set an event listener on "mediaready" to update the trackevent after the base duration has been changed
if ( options.end && options.end > _butter.duration ) {
playWhenReady = !_butter.currentMedia.paused;
_butter.currentMedia.url = "#t=," + options.end;
_butter.listen( "mediaready", updateEndAfterExpand );
} else {
Expand Down
Expand Up @@ -88,6 +88,9 @@
clearTimeout( options.loadTimeout );
// If teardown was hit before ready, ensure we teardown.
if ( options._cancelLoad ) {
if ( options.playWhenReady ) {
_this.play();
}
options._cancelLoad = false;
options.tearDown();
}
Expand Down

0 comments on commit 50a9bd1

Please sign in to comment.