forked from mediaelement/mediaelement
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mep-feature-playpause.js
68 lines (57 loc) · 1.52 KB
/
mep-feature-playpause.js
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
64
65
66
67
68
(function($) {
$.extend(mejs.MepDefaults, {
playText: mejs.i18n.t('Play'),
pauseText: mejs.i18n.t('Pause')
});
// PLAY/pause BUTTON
$.extend(MediaElementPlayer.prototype, {
buildplaypause: function(player, controls, layers, media) {
var
t = this,
op = t.options,
play =
$('<div class="mejs-button mejs-playpause-button mejs-play" >' +
'<button type="button" aria-controls="' + t.id + '" title="' + op.playText + '" aria-label="' + op.playText + '"></button>' +
'</div>')
.appendTo(controls)
.click(function(e) {
e.preventDefault();
if (media.paused) {
media.play();
} else {
media.pause();
}
return false;
}),
play_btn = play.find('button');
function togglePlayPause(which) {
if ('play' === which) {
play.removeClass('mejs-play').addClass('mejs-pause');
play_btn.attr({
'title': op.pauseText,
'aria-label': op.pauseText
});
} else {
play.removeClass('mejs-pause').addClass('mejs-play');
play_btn.attr({
'title': op.playText,
'aria-label': op.playText
});
}
};
togglePlayPause('pse');
media.addEventListener('play',function() {
togglePlayPause('play');
}, false);
media.addEventListener('playing',function() {
togglePlayPause('play');
}, false);
media.addEventListener('pause',function() {
togglePlayPause('pse');
}, false);
media.addEventListener('paused',function() {
togglePlayPause('pse');
}, false);
}
});
})(mejs.$);