Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Mp3 sound clip on mouseclick using jplayer?

Actually this the first time I'm gonna use jplayer plugin, so all I need is to play a sound clip (2 sec) when I click on a div, and I don't know how to use jplayer!

I also need to load the sound clip file in cache as well as the page is loading, so when I click that div the sound clip plays immediately without loading it when clicking

btw, is it possible to do that without using jplayer, jquery maybe?!

like image 619
Sam Avatar asked Jun 02 '11 14:06

Sam


2 Answers

If you want to stick with jPlayer, try setting warningAlerts and errorAlerts to true.

$(id).jPlayer( { warningAlerts: true, errorAlerts: true } );

This may solve your problem.

But as long as you only need sound (no video), SoundManager 2 might be a better fit for you. Its really robust and provides extensive debugging output.

soundManager.url = './swf/'; // directory where SM2 .SWFs live

var mySound;

soundManager.onready(function() {

    // SM2 has loaded - now you can create and play sounds!

    mySound = soundManager.createSound({
      id: 'someSound',
      url: '/path/to/some.mp3'
    });
});

//....
//if(xhr-stuff)
    if(mySound)
        mySound.play();

Use soundmanager2.js for testing and soundmanager2-nodebug-jsmin.js for production. If you have further questions, don't hesistate to ask.

like image 76
Maximilian Hils Avatar answered Oct 05 '22 23:10

Maximilian Hils


-snip-

scratch that... there's an api

http://www.jplayer.org/latest/developer-guide/#jPlayer-play

Use

$("#jpId").jPlayer("play");
like image 29
Joseph Marikle Avatar answered Oct 06 '22 00:10

Joseph Marikle