Re-instantiate the `MediaElementPlayer` instance when switching mime types in playlists.

Fixes #27608.


Built from https://develop.svn.wordpress.org/trunk@27871


git-svn-id: http://core.svn.wordpress.org/trunk@27702 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-03-31 15:35:15 +00:00
parent 7efc48c365
commit 55b61b7a70
2 changed files with 48 additions and 23 deletions

View File

@ -4,13 +4,9 @@
"use strict";
var WPPlaylistView = Backbone.View.extend({
index : 0,
itemTemplate : wp.template('wp-playlist-item'),
initialize : function (options) {
var settings = {};
this.index = 0;
this.settings = {};
this.data = options.metadata || $.parseJSON( this.$('script').html() );
this.playerNode = this.$( this.data.type );
@ -18,27 +14,57 @@
this.current = this.tracks.first();
if ( 'audio' === this.data.type ) {
this.currentTemplate = wp.template('wp-playlist-current-item');
this.currentTemplate = wp.template( 'wp-playlist-current-item' );
this.currentNode = this.$( '.wp-playlist-current-item' );
}
this.renderCurrent();
if ( this.data.tracklist ) {
this.itemTemplate = wp.template( 'wp-playlist-item' );
this.playingClass = 'wp-playlist-playing';
this.renderTracks();
}
this.playerNode.attr( 'src', this.current.get('src') );
this.playerNode.attr( 'src', this.current.get( 'src' ) );
_.bindAll( this, 'bindPlayer', 'ended', 'clickTrack' );
_.bindAll( this, 'bindPlayer', 'bindResetPlayer', 'setPlayer', 'ended', 'clickTrack' );
if ( ! _.isUndefined( window._wpmejsSettings ) ) {
settings.pluginPath = _wpmejsSettings.pluginPath;
this.settings.pluginPath = _wpmejsSettings.pluginPath;
}
settings.success = this.bindPlayer;
this.settings.success = this.bindPlayer;
this.setPlayer();
},
this._player = new MediaElementPlayer( this.playerNode.get(0), settings );
bindPlayer : function (mejs) {
this.player = mejs;
this.player.addEventListener( 'ended', this.ended );
},
bindResetPlayer : function (mejs) {
this.bindPlayer( mejs );
this.playCurrentSrc();
},
setPlayer: function () {
if ( this._player ) {
this._player.pause();
this._player.remove();
this.playerNode = this.$( this.data.type );
this.playerNode.prop( 'src', this.current.get( 'src' ) );
this.settings.success = this.bindResetPlayer;
}
/**
* This is also our bridge to the outside world
*/
this._player = new MediaElementPlayer( this.playerNode.get(0), this.settings );
},
playCurrentSrc : function () {
this.renderCurrent();
this.player.load();
this.player.play();
},
renderCurrent : function () {
@ -79,11 +105,6 @@
'click .wp-playlist-prev' : 'prev'
},
bindPlayer : function (mejs) {
this.player = mejs;
this.player.addEventListener( 'ended', this.ended );
},
clickTrack : function (e) {
this.index = this.$( '.wp-playlist-item' ).index( e.currentTarget );
this.setCurrent();
@ -110,10 +131,17 @@
},
loadCurrent : function () {
var last = this.playerNode.attr( 'src' ).split('.').pop(),
current = this.current.get( 'src' ).split('.').pop();
this.player.pause();
this.playerNode.attr( 'src', this.current.get( 'src' ) );
this.renderCurrent();
this.player.load();
if ( last !== current ) {
this.setPlayer();
} else {
this.playerNode.prop( 'src', this.current.get( 'src' ) );
this.playCurrentSrc();
}
},
setCurrent : function () {
@ -127,7 +155,6 @@
}
this.loadCurrent();
this.player.play();
}
});

View File

@ -2529,8 +2529,6 @@ function wp_enqueue_media( $args = array() ) {
'suggestedWidth' => __( 'Suggested width is %d pixels.' ),
'suggestedHeight' => __( 'Suggested height is %d pixels.' ),
'mediaHTML5Text' => __( 'Add alternate sources for maximum HTML5 playback:' ),
// Edit Audio
'audioDetailsTitle' => __( 'Audio Details' ),
'audioReplaceTitle' => __( 'Replace Audio' ),