要把它们放在酒吧里,你可以忽略那些漂亮的WP播放列表,使用mediaelement添加你自己的。js直接,类似于this question.
你基本上扩展了MediaElementPlayer
通过书写buildXXX
函数,然后在设置中指定它们features
属性作为数组(以及所有其他控件)。
下面通过挂接wp_playlist_scripts
行动的优先顺序为9,足够早,有望延长MediaElementPlayer
和WP_wpmejsSettings
在创建播放列表之前启动wp-mediaelement
.
(为了简单起见dashicons
此处用于设置样式。)
add_action( \'wp_playlist_scripts\', function () {
wp_enqueue_style( \'dashicons\' );
?>
<style>
.mejs-prev span, .mejs-next span {
color:#eee; cursor:pointer; display:inline-block; font-family:"dashicons"; margin-top:5px;
}
</style>
<script>
(function ($) {
if (typeof MediaElementPlayer !== \'undefined\' && typeof _wpmejsSettings !== \'undefined\') {
$.extend(MediaElementPlayer.prototype, {
buildprev: function(player, controls, layers, media) {
var tracks = $(\'.wp-playlist-tracks .wp-playlist-item\', controls.closest(\'.wp-playlist\'));
if (tracks.length > 1) {
$(\'<div class="mejs-button mejs-prev-button mejs-prev" >\' +
\'<span class="dashicons dashicons-arrow-left-alt2" title="\' + this.options.prevText + \'"></span>\' +
\'</div>\').appendTo(controls).on(\'click\', function (event) {
event.stopPropagation();
tracks.each(function (index) {
if ($(this).hasClass(\'wp-playlist-playing\') ) {
index = (index - 1) % tracks.length;
tracks.get(index).click();
return false;
}
});
});
}
},
buildnext: function(player, controls, layers, media) {
var tracks = $(\'.wp-playlist-tracks .wp-playlist-item\', controls.closest(\'.wp-playlist\'));
if (tracks.length > 1) {
$(\'<div class="mejs-button mejs-next-button mejs-next" >\' +
\'<span class="dashicons dashicons-arrow-right-alt2" title="\' + this.options.nextText + \'"></span>\' +
\'</div>\').appendTo(controls).on(\'click\', function (event) {
event.stopPropagation();
tracks.each(function (index) {
if ($(this).hasClass(\'wp-playlist-playing\') ) {
index = (index + 1) % tracks.length;
tracks.get(index).click();
return false;
}
});
});
}
}
});
$.extend(_wpmejsSettings, {
// Put these in the order you want.
features: [\'playpause\',\'current\',\'progress\',\'duration\',\'tracks\',\'volume\',\'fullscreen\',\'prev\',\'next\'],
prevText: <?php echo json_encode( __( \'Previous track\' ) ); ?>,
nextText: <?php echo json_encode( __( \'Next track\' ) ); ?>
});
}
})(jQuery);
</script>
<?php
}, 9 );