[英]How to go back 5 secs back while playing in Titanium, on button click this should happen
我有以下代碼。
var file = recording.stop();
sound = Titanium.Media.createSound({sound:file});
sound.play();
sound.getTime(); // This will return the current time position of the audio.
var goBack = Titanium.UI.createButton({title:'Go Back',height:40,width:200,top:230});
goBack.addEventListener('click',function(){
if(sound.playing){
Ti.API.info(sound.getTime()); // If this prints 25 secs.
}
});
win.add(goBack);
假設當前的getTime()
返回 25,我需要在單擊按鈕時從 20 秒開始播放音頻。
我該怎么做呢?
我可以使用這樣的東西
setTime = sound.getTime() - 5
但是我們如何將浮點值傳遞給 sound.setTime?
還有有沒有什么辦法可以添加搜索欄來指示聲音 object 的播放狀態?
您可以像這樣設置時間值:
sound.time = 20.0; // assuming that you want to start the sound from 20th second.
您可以像這樣添加進度條:
var pb = Titanium.UI.createProgressBar({
min:0,
value:0,
width:200
});
//when you play the sound set
pb.max = sound.duration;
// when your sound is complete
sound.addEventListener('complete', function()
{
pb.value = 0;
});
// and also add this code to your file
//INTERVAL TO UPDATE PB
var i = setInterval(function()
{
if (sound.isPlaying())
{
Ti.API.info('time ' + sound.time);
pb.value = sound.time;
}
},500);
// CLOSE EVENT - CANCEL INTERVAL
win.addEventListener('close', function()
{
clearInterval(i);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.