Как вернуться назад на 5 секунд во время игры в Titanium, при нажатии кнопки это должно произойти - PullRequest
1 голос
/ 14 июня 2011

У меня есть следующий код.

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);

Предполагая, что currect getTime() возвращает 25, и мне нужно воспроизвести звук от 20 секунд при нажатии кнопки.

Как мне это сделать?

Я могу использовать что-то вроде этого

setTime = sound.getTime() - 5

Но как мы передаем значение с плавающей точкой в ​​sound.setTime?

А также есть ли способ добавить строку поиска, чтобы указать состояние воспроизведения звукового объекта?

1 Ответ

1 голос
/ 14 июня 2011

Вы можете установить значение времени следующим образом:

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);
    });
...