Make WordPress Core

Changeset 27871


Ignore:
Timestamp:
03/31/2014 03:34:23 PM (11 years ago)
Author:
wonderboymusic
Message:

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

Fixes #27608.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/mediaelement/wp-playlist.js

    r27640 r27871  
    55
    66    var WPPlaylistView = Backbone.View.extend({
    7         index : 0,
    8 
    9         itemTemplate : wp.template('wp-playlist-item'),
    10 
    117        initialize : function (options) {
    12             var settings = {};
    13 
     8            this.index = 0;
     9            this.settings = {};
    1410            this.data = options.metadata || $.parseJSON( this.$('script').html() );
    1511            this.playerNode = this.$( this.data.type );
     
    1915
    2016            if ( 'audio' === this.data.type ) {
    21                 this.currentTemplate = wp.template('wp-playlist-current-item');
     17                this.currentTemplate = wp.template( 'wp-playlist-current-item' );
    2218                this.currentNode = this.$( '.wp-playlist-current-item' );
    2319            }
     
    2622
    2723            if ( this.data.tracklist ) {
     24                this.itemTemplate = wp.template( 'wp-playlist-item' );
    2825                this.playingClass = 'wp-playlist-playing';
    2926                this.renderTracks();
    3027            }
    3128
    32             this.playerNode.attr( 'src', this.current.get('src') );
     29            this.playerNode.attr( 'src', this.current.get( 'src' ) );
    3330
    34             _.bindAll( this, 'bindPlayer', 'ended', 'clickTrack' );
     31            _.bindAll( this, 'bindPlayer', 'bindResetPlayer', 'setPlayer', 'ended', 'clickTrack' );
    3532
    3633            if ( ! _.isUndefined( window._wpmejsSettings ) ) {
    37                 settings.pluginPath = _wpmejsSettings.pluginPath;
     34                this.settings.pluginPath = _wpmejsSettings.pluginPath;
    3835            }
    39             settings.success = this.bindPlayer;
     36            this.settings.success = this.bindPlayer;
     37            this.setPlayer();
     38        },
    4039
    41             this._player = new MediaElementPlayer( this.playerNode.get(0), settings );
     40        bindPlayer : function (mejs) {
     41            this.player = mejs;
     42            this.player.addEventListener( 'ended', this.ended );
     43        },
     44
     45        bindResetPlayer : function (mejs) {
     46            this.bindPlayer( mejs );
     47            this.playCurrentSrc();
     48        },
     49
     50        setPlayer: function () {
     51            if ( this._player ) {
     52                this._player.pause();
     53                this._player.remove();
     54                this.playerNode = this.$( this.data.type );
     55                this.playerNode.prop( 'src', this.current.get( 'src' ) );
     56                this.settings.success = this.bindResetPlayer;
     57            }
     58            /**
     59             * This is also our bridge to the outside world
     60             */
     61            this._player = new MediaElementPlayer( this.playerNode.get(0), this.settings );
     62        },
     63
     64        playCurrentSrc : function () {
     65            this.renderCurrent();
     66            this.player.load();
     67            this.player.play();
    4268        },
    4369
     
    80106        },
    81107
    82         bindPlayer : function (mejs) {
    83             this.player = mejs;
    84             this.player.addEventListener( 'ended', this.ended );
    85         },
    86 
    87108        clickTrack : function (e) {
    88109            this.index = this.$( '.wp-playlist-item' ).index( e.currentTarget );
     
    111132
    112133        loadCurrent : function () {
     134            var last = this.playerNode.attr( 'src' ).split('.').pop(),
     135                current = this.current.get( 'src' ).split('.').pop();
     136
    113137            this.player.pause();
    114             this.playerNode.attr( 'src', this.current.get( 'src' ) );
    115             this.renderCurrent();
    116             this.player.load();
     138
     139            if ( last !== current ) {
     140                this.setPlayer();
     141            } else {
     142                this.playerNode.prop( 'src', this.current.get( 'src' ) );
     143                this.playCurrentSrc();
     144            }
    117145        },
    118146
     
    128156
    129157            this.loadCurrent();
    130             this.player.play();
    131158        }
    132159    });
  • trunk/src/wp-includes/media.php

    r27869 r27871  
    25302530        'suggestedHeight' => __( 'Suggested height is %d pixels.' ),
    25312531
    2532         'mediaHTML5Text'        => __( 'Add alternate sources for maximum HTML5 playback:' ),
    2533 
    25342532        // Edit Audio
    25352533        'audioDetailsTitle'     => __( 'Audio Details' ),
Note: See TracChangeset for help on using the changeset viewer.