admin管理员组文章数量:1391987
I wanted to add a extra button "HD" near caption inside html5 player. Added this piece of code inside mediaelementplayer.js file.
//HD button display starts
(function ($) {
$.extend(MediaElementPlayer.prototype, {
buildcontextmenu: function (player, controls, layers, media) {
// create HD button
$('<div class="mejs-button mejs-hd-button"><span>HD<span/></div>')
.appendTo(controls);
}
});
})(mejs.$);
//HD button display stops
can anyone help to solve this issue? As of now mediaelementplayer.js by johndyer doesnot support HD on/off button. Reference / by johndyer
I wanted to add a extra button "HD" near caption inside html5 player. Added this piece of code inside mediaelementplayer.js file.
//HD button display starts
(function ($) {
$.extend(MediaElementPlayer.prototype, {
buildcontextmenu: function (player, controls, layers, media) {
// create HD button
$('<div class="mejs-button mejs-hd-button"><span>HD<span/></div>')
.appendTo(controls);
}
});
})(mejs.$);
//HD button display stops
can anyone help to solve this issue? As of now mediaelementplayer.js by johndyer doesnot support HD on/off button. Reference http://mediaelementjs./ by johndyer
Share Improve this question asked Feb 12, 2015 at 6:22 Asif IqbalAsif Iqbal 5431 gold badge10 silver badges29 bronze badges2 Answers
Reset to default 5You need to do it as follows (this is an example for a Loop button):
MediaElementPlayer.prototype.buildloop = function(player, controls, layers, media) {
var
// create the loop button
loop =
$('<div class="mejs-button mejs-loop-button ' + ((player.options.loop) ? 'mejs-loop-on' : 'mejs-loop-off') + '">' +
'<span></span>' +
'</div>')
// append it to the toolbar
.appendTo(controls)
// add a click toggle event
.click(function() {
player.options.loop = !player.options.loop;
if (player.options.loop) {
loop.removeClass('mejs-loop-off').addClass('mejs-loop-on');
} else {
loop.removeClass('mejs-loop-on').addClass('mejs-loop-off');
}
});
}
Then, when creating your video player you can just add your variable to the features list for example:
$('video,audio').mediaelementplayer({
features: ['loop','playpause','current','progress','duration','fullscreen'],
alwaysShowControls: true,
});
Thank you @Sam, i used your code and wrote a vanilla version of your solution. This one adds two buttons to adjust the volume, a plus and a minus button, to make 10 steps for adjustment. (mediaelementjs 4.2.8)
Javascript:
var audio_player = document.getElementById('audio-player').children[0];
MediaElementPlayer.prototype.buildvolume_plus = function(player, controls) {
var
volume = document.createElement('div'),
volume_button = document.createElement('button');
volume.className = 'mejs__button mejs__volumeplus-button';
volume_button.type = 'button';
volume.appendChild(volume_button);
controls.appendChild(volume);
volume_button.addEventListener('click', function() {
player.setVolume( player.volume < 1 ? Math.round( (player.volume + .1 ) * 10) / 10 : 1 );
})
};
MediaElementPlayer.prototype.buildvolume_minus = function(player, controls) {
var
volume = document.createElement('div'),
volume_button = document.createElement('button');
volume.className = 'mejs__button mejs__volumeminus-button';
volume_button.type = 'button';
volume.appendChild(volume_button);
controls.appendChild(volume);
volume_button.addEventListener('click', function() {
player.setVolume( player.volume > 0 ? Math.round( (player.volume - .1 ) * 10) / 10 : 0 );
})
};
new MediaElementPlayer(audio_player);
HTML:
<div id="audio-player">
<audio src="http://example." width="220" height="60" controls data-mejsoptions=\'{"features": ["playpause", "volume_plus", "volume_minus"]}\'></audio>
</div>
本文标签:
版权声明:本文标题:javascript - how to add custom button inside html player using mediaelement,js script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744759917a2623692.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论