-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmedia-playback-speed.php
63 lines (58 loc) · 2.08 KB
/
media-playback-speed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Plugin Name: Media Playback Speed
* Description: Appends playback buttons to the Media Player.
* Author: Daron Spence
* Version: 0.1
*/
add_action( 'wp_enqueue_scripts', function(){
wp_enqueue_script( 'jquery' );
});
add_action( 'wp_footer', function(){
?>
<style>
.mejs-button.blank-button>button {
background: transparent;
color: #ccc;
font-size: 1em;
width: auto;
}
</style>
<script type="text/template" id="playback-buttons-template">
<div class="mejs-button blank-button">
<button type="button" class="playback-rate-button" data-value="0.5" title="Playback Speed 0.5x" aria-label="Playback Speed 0.5x" tabindex="0">.5x</button>
</div>
<div class="mejs-button blank-button">
<button type="button" class="playback-rate-button" data-value="1" title="Playback Speed 1x" aria-label="Playback Speed 1x" tabindex="0">1x</button>
</div>
<div class="mejs-button blank-button">
<button type="button" class="playback-rate-button" data-value="1.5" title="Playback Speed 1.5x" aria-label="Playback Speed 1.5x" tabindex="0">1.5x</button>
</div>
<div class="mejs-button blank-button">
<button type="button" class="playback-rate-button" data-value="2" title="Playback Speed 2x" aria-label="Playback Speed 2x" tabindex="0">2x</button>
</div>
</script>
<script type="text/javascript">
(function($){
$(window).load( function(){
var $buttons = $( $("#playback-buttons-template").html() );
var $els = $( '.mejs-container' );
for ( i = 0; i < $els.length; i++ ){
var audioTag = $( $els[i] ).find('audio,video')[0];
$buttons.find('.playback-rate-button').attr('aria-controls', audioTag.id );
var $controls = $( $els[i] ).find('.mejs-controls');
if($controls.length > 0) {
$controls.find('.mejs-duration-container').after( $buttons.clone() );
}
}
$('body').on('click', '.playback-rate-button', function() {
var btnEl = $(this),
mediaTag = $('#'+btnEl.attr('aria-controls'))[0],
rate = btnEl.attr('data-value');
mediaTag.setPlaybackRate(rate);
});
});
})(jQuery);
</script>
<?php
}, 1, 100 );