How to pause the mediaelementjs player on a button click?
i am using mediaelementjs to play video on my web page. I want pause the media if it playing on a button click.i tried do it but didn't work.
here is the code:
开发者_JAVA百科 var my_media=jQuery('audio,video').mediaelementplayer(
{
success: function(player, node)
{
jQuery('#' + node.id + '-mode').html('mode: ' + player.pluginType)
}
});
jQuery('#rightControlarrow').click(function(){
my_media.pause();
});
I don't have any experience with this plugin, but I think that the multiple selectors ('audio,video') are your problem. This could be causing some DOM confusion as to which element is being referenced when you call 'pause'. So try just adding one per object (i.e. $('video').mediaelementlayer(. . .);
Press F12 in your browser to catch JavaScript errors and also make use of the "error" property of MediaElement to give yourself some feedback when something goes wrong.
Also, I don't see where you are calling the play method ( mediaElement.play();).
If you want to post more script and markup I will be happy to take a look tomorrow to see if there are other issues.
Take care,
Matt
I got the answer
my_media = new Array();
jQuery('audio,video').mediaelementplayer(
{
success: function(player, node)
{
jQuery('#' + node.id + '-mode').html('mode: ' + player.pluginType);
my_media.push(player);
}
});
jQuery('#rightControlarrow').click(function(){
my_media[0].pause();
});
精彩评论