经过5次的PhoneGap媒体声音停止播放 [英] phonegap media sound stop playing after 5 times
问题描述
我需要发挥正确的声音,如果用户正确与错,如果不正确回答这个问题。播放声音时在第一,但之后的第五次我答对其中输出第四次正确的声音已经是第五次,没有发出任何声音。看来音乐只能起到最多4次。 是什么造成这种可能的原因是什么?
更新* 我说media.release在我stopAudio(),但到目前为止的声音能听到6日(改善),但它仍然是不适合我的情况。 (需要同样的音效许多问题)
Js.file
//音频播放器
VAR my_media = NULL;
VAR mediaTimer = NULL;
//播放音频
功能playAudio(SRC){
//创建一个从SRC媒体对象
my_media =新媒体(SRC,空,soundCB);
my_media.play();
}
功能soundCB(ERR){
的console.log(playAudio():音频错误:+ ERR);
}
//停止音频
//
功能stopAudio(){
如果(my_media){
警报(AQA);
my_media.stop();
my_media.release();
}
clearInterval(mediaTimer);
mediaTimer = NULL;
}
/////问题部分//////
$(#答案)。生活('水龙头',函数(事件){
如果(buttonAns ==真){
$此= $(本);
buttonAns = FALSE;
VAR的选择= $ this.attr(类);
如果((correctAnsNo == 0&安培;&安培;选择==answer0)||(correctAnsNo == 1&安培;&安培;选择==answer1)||(correctAnsNo == 2&安培;&安培;选择== answer2)){
playAudio('/ android_asset /网络/音频/ fall.mp3'); //坠落的声音
正确= parseInt函数(正确的)+2;
playAudio('/ android_asset /网络/音频/ correct.mp3'); //叮咚
}其他{
playAudio('/ android_asset /网络/音频/ wrong1.wav');
}
如果(quesNo< wordsNo){
的setTimeout(函数(){
buttonAns = TRUE;
db.transaction(queryQuesDB,errorCB);
},1800);
}其他{
endLevel();
}
} 其他 {
。事件preventDefault();
}
});
Android已经以播放声音资源有限的。你不断创造新的媒体对象要播放的文件每次。你需要释放你不使用的声音。如果你需要播放这些声音多次,每次再考虑创建单独的媒体对象持有的引用,这些声音。
阅读上的<一个href="http://docs.phonegap.com/en/2.2.0/cordova_media_media.md.html#media.release">media.release.
I need to play the "correct" sound if user answer the question correctly and "wrong" if incorrect. The sound is playing at first but after at the fifth time I answer correctly which output the fourth time "correct" sound already the fifth time, no sound can be heard. It seems the music can only played at most 4th times. What is the possible reason that cause this?
updated* I added media.release in my stopAudio() but so far the sound can be heard for 6th (improved) but it is still not suits my case. (Many questions that need the same sound effect)
Js.file
// Audio player
var my_media = null;
var mediaTimer = null;
// Play audio
function playAudio(src) {
// Create Media object from src
my_media = new Media(src, null, soundCB);
my_media.play();
}
function soundCB(err){
console.log("playAudio():Audio Error: "+err);
}
// Stop audio
//
function stopAudio() {
if (my_media) {
alert("AQA");
my_media.stop();
my_media.release();
}
clearInterval(mediaTimer);
mediaTimer = null;
}
/////question part//////
$("#answer").live('tap', function(event){
if(buttonAns==true) {
$this= $(this);
buttonAns = false;
var choice = $this.attr("class");
if((correctAnsNo == 0 && choice =="answer0")||(correctAnsNo == 1 && choice =="answer1")||(correctAnsNo == 2 && choice =="answer2")){
playAudio('/android_asset/www/audio/fall.mp3'); //falling sound
correct = parseInt(correct)+2;
playAudio('/android_asset/www/audio/correct.mp3'); //dingdong
}else{
playAudio('/android_asset/www/audio/wrong1.wav');
}
if(quesNo < wordsNo ){
setTimeout(function() {
buttonAns = true;
db.transaction(queryQuesDB, errorCB);
},1800);
}else{
endLevel();
}
} else {
event.preventDefault();
}
});
Android has a finite amount of resources in order to play sounds. You keep creating a new Media object each time you want to play a file. You need to release the sounds you are not using. If you need to play those sounds multiple times each then consider creating separate media objects to hold a reference to those sounds.
Read up on media.release.
这篇关于经过5次的PhoneGap媒体声音停止播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!