如何在 Titanium 中玩游戏时返回 5 秒,点击按钮就会发生这种情况

发布于 2024-11-15 10:32:31 字数 680 浏览 3 评论 0原文

我有以下代码。

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 ?

还有有没有办法添加搜索栏来指示声音对象的播放状态?

I have the following code.

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

Assuming that currect getTime() returns 25 and i need to play the audio from 20 secs on button click.

How do i do this?

I can use something like this

setTime = sound.getTime() - 5

But How do we pass the float value to sound.setTime?

And also Is there any way to add seek bar to indicate the play status of the sound object?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房敞 2024-11-22 10:32:31

您可以像这样设置时间值:

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

You can set the time value like this:

sound.time = 20.0; // assuming that you want to start the sound from 20th second.

You can add a progress bar like this:

     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);
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文