diff --git a/src/wp-includes/js/media-views.js b/src/wp-includes/js/media-views.js
index 8d4bf43d00..462386b19b 100644
--- a/src/wp-includes/js/media-views.js
+++ b/src/wp-includes/js/media-views.js
@@ -6384,6 +6384,7 @@
_.bindAll(this, 'success', 'close');
this.listenTo( this.controller, 'close', this.close );
+ this.on( 'ready', this.setPlayer );
media.view.Settings.AttachmentDisplay.prototype.initialize.apply( this, arguments );
},
@@ -6411,7 +6412,16 @@
},
setPlayer : function () {
- this.player = false;
+ if ( ! this.player ) {
+ this.player = new MediaElementPlayer( this.media, this.settings );
+ }
+ },
+
+ /**
+ * @abstract
+ */
+ setMedia : function () {
+ return this;
},
/**
@@ -6449,8 +6459,11 @@
close : function() {
if ( this.player ) {
- this.mejs.pause();
+ if ( _.isUndefined( this.mejs.pluginType ) ) {
+ this.mejs.pause();
+ }
this.remove();
+ this.player = false;
}
},
@@ -6478,9 +6491,9 @@
media.view.Settings.AttachmentDisplay.prototype.render.apply( this, arguments );
setTimeout( function() { self.resetFocus(); }, 10 );
- this.setPlayer( settings );
+ this.settings = settings;
- return this;
+ return this.setMedia();
},
resetFocus: function() {
@@ -6503,12 +6516,11 @@
className: 'audio-details',
template: media.template('audio-details'),
- setPlayer: function( settings ) {
+ setMedia: function() {
var audio = this.$('.wp-audio-shortcode').get(0);
- audio = this.prepareSrc( audio );
+ this.media = this.prepareSrc( audio );
- this.player = new MediaElementPlayer( audio, settings );
return this;
}
});
@@ -6528,12 +6540,17 @@
className: 'video-details',
template: media.template('video-details'),
- setPlayer: function( settings ) {
- var video = this.$('.wp-video-shortcode').get(0);
+ setMedia: function() {
+ var video = this.$('.wp-video-shortcode');
- video = this.prepareSrc( video );
+ if ( ! video.hasClass('youtube-video') ) {
+ video = this.prepareSrc( video.get(0) );
+ } else {
+ video = video.get(0);
+ }
+
+ this.media = video;
- this.player = new MediaElementPlayer( video, settings );
return this;
}
});
diff --git a/src/wp-includes/media-template.php b/src/wp-includes/media-template.php
index 54b9780559..6bad9a361a 100644
--- a/src/wp-includes/media-template.php
+++ b/src/wp-includes/media-template.php
@@ -739,11 +739,41 @@ function wp_print_media_templates() {
var w = ! data.model.width || data.model.width > 640 ? 640 : data.model.width,
h = ! data.model.height ? 360 : data.model.height;
- if ( w !== data.model.width ) {
+ if ( data.model.width && w !== data.model.width ) {
h = Math.ceil( ( h * w ) / data.model.width );
}
- if ( data.model.src ) { #>
+ if ( data.model.src ) {
+ if ( data.model.src.match(/youtube|youtu\.be/) ) {
+ #>
+
+ <#
+ } else {
+ #>