开发者

Play Mp3 sound clip on mouseclick using jplayer?

开发者 https://www.devze.com 2023-03-09 20:36 出处:网络
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!

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?!


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.


-snip-

scratch that... there's an api

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

Use

$("#jpId").jPlayer("play");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号