Jim Hyland
Jim Hyland

Reputation: 239

Play mediaelement.js audio via jquery click

Not sure why this is happening or how to get around it. I'm trying to trigger a sound by clicking on a div with class .button

$('.button').click(function(){
    $('audio')[0].player.play();
});

Works great on everything except firefox.

$('.button').click(function(){
    $('audio')[0].play();
});

Without the .player Works great on everything except iOS!

Not sure what I can do here.

Upvotes: 1

Views: 2474

Answers (1)

souporserious
souporserious

Reputation: 2157

I know this is an old question, but I found an answer to this problem if anyone hasn't yet!

Use the following (works on IOS as well as FF)

$('audio').mediaelementplayer({
 success: function(media, domElement, player) {
   $('.play').on('click', function() {
     media.play();
   });
   $('.pause').on('click', function() {
     media.pause();
   });
 }
});

This would use a button or whatever with a class of "play" and the other with a class of "pause" to use externally from the player or whatever your hearts desire. Hope this helps!

Upvotes: 3

Related Questions