简体   繁体   English

Phonegap / Jquery Mobile Android App如果出现问题

[英]Phonegap/ Jquery Mobile Android App If Issue

I'm having issues with a fairly basic If statement that I'm using to trigger a music playing sequence. 我使用基本的If语句来触发音乐播放序列时遇到问题。 It's for an automated preview button. 这是一个自动预览按钮。 Basically Its a pretty average preview - t the user clicks a button - the preview plays - and the button image switches to a pause icon , click again and the track will stop playing and image will switch back. 基本上,这是一个相当平均的预览-用户单击按钮-预览将播放-且按钮图像切换到暂停图标,再次单击,曲目将停止播放,图像将切换回去。

I've currently got the following script - 我目前有以下脚本-

var playingTwo=false;
var playthis=null;

function previewThis(preview){
playthis = "/android_asset/www/" +"Paradise"+".mp3"
prevMedia= new Media(playthis, stopAudio, null);
playPrev();
}




function playPrev() {
if (!playingTwo) {
    prevMedia.play();
            $('.playBtnPrev').removeClass('sel')
    playVarTwo(); 

} else {
    prevMedia.stop();
            $('.playBtnPrev').addClass('sel')
    pauseVarTwo();              
}
}



function playVarTwo(){setTimeout( function() {

    playingTwo = true; 
}, 1000 );}


function pauseVarTwo(){setTimeout( function() {
playingTwo = false; 

}, 1000 );

}


  $('.playBtnPrev').live('tap',function(event) {previewThis();});

Basically the previewThis() script will eventually have the track name passed to it, it sets up the media location and triggers the playPrev() script - the play button detects whether or not its already playing - if not it plays - if its already playing it pauses and switches the images according - all fairly straightforward. 基本上,previewThis()脚本最终将获得音轨名称,它会设置媒体位置并触发playPrev()脚本-播放按钮检测其是否已经在播放-如果不是,则播放-如果已经在播放它会暂停并根据图像切换图像-所有操作都非常简单。

Initially I wrapped all the state functions in each If statement - although this worked fine in a browser - on mobile the If statement ran both state - so it would stop and start the track with a second gap. 最初,我将所有状态函数包装在每个If语句中-尽管这在浏览器中可以正常工作-在移动设备上,If语句同时运行两个状态-因此它将停止并以第二个间隔开始跟踪。 So I split the state change into a set timeout function to make the if complete before the state changed - but still no joy, now it plays the track twice(overlapping), so its driving me insane! 因此,我将状态更改拆分为一个设置的超时功能,以使状态更改之前如果完成-但仍然没有喜悦,现在它播放了两次曲目(重叠),所以让我发疯了!

Can anyone offer any advice please? 任何人都可以提供任何建议吗?

Cheers Paul 干杯保罗

I include your code in a existing jquerymobile mine, and after comment some function like the part of instancing a Media object... 我将您的代码包含在现有的jquerymobile矿井中,并在注释后添加了一些功能,例如实例化Media对象的一部分...

I see an error: 我看到一个错误:

"playingTwo is not defined" “ playingTwo未定义”

I think that you must set var playingTwo; 我认为您必须设置var playingTwo; before the function previewThis. 在功能预览之前。

Let me know if this solve the problem. 让我知道这是否可以解决问题。

Good Luck! 祝好运!

as @Mariano wrote, I would suggest adding at the top of your file: 正如@Mariano所写,我建议在文件顶部添加:

 var playingTwo = false;

since it's probably not assigned (nor created) when you are already checking for it's value. 因为您已经在检查它的值时可能未分配(也未创建)。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM