首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何在播放远程mp3时添加进度条

如何在播放远程mp3时添加进度条
EN

Stack Overflow用户
提问于 2012-03-17 09:57:36
回答 1查看 2.1K关注 0票数 0

我正在播放一个远程mp3音频文件,我只想添加一个进度条和一个标签,以显示还有多少时间。

我怎么能这么做。我使用下面的代码来播放远程mp3文件。

我代码的链接在这里!

http://pastie.org/3613911

EN

回答 1

Stack Overflow用户

发布于 2012-03-17 14:18:23

编辑的

如果要显示进度条,则需要mp3文件的总持续时间。但是,使用当前的钛1.8SDK,您无法从远程文件()的音频播放器 (.mp3)中获得的总持续时间。但是,您仍然可以从后端获得总持续时间。例如,在您的响应中设置总持续时间标记,并在进度的最大大小中使用它。

代码语言:javascript
代码运行次数:0
运行
复制
//assing total duration in milliseconds and divide by 1000 from your server

var totalDurationFromBackend = 898 // its in your case.Also divided by 1000 

var audioPlayer = Ti.Media.createAudioPlayer({ 

    url: 'http://naturallyimprove.com/mp3/Drone.mp3',
    allowBackground: true
});

var pb=Titanium.UI.createProgressBar
({
   top:10,
   width:250,
   height:'auto',
   min:0,
   max:totalDurationFromBackend,
   value:0,
   color:'#fff',
   style:Titanium.UI.iPhone.ProgressBarStyle.PLAIN,
});
win.add(pb);
pb.show();

audioPlayer.addEventListener('progress',function(e) 
{
   Ti.API.info('Time Played: ' + Math.round(e.progress) + ' milliseconds');

   // set the progress bar's progress value with current time played.. (milliseconds) 
   pb.value =  Math.round(e.progress/1000) ; 
});

startStopButton.addEventListener('click',function() {

// When paused, playing returns false.
// If both are false, playback is stopped.
if (audioPlayer.playing || audioPlayer.paused)
{
    audioPlayer.stop();
    pauseResumeButton.enabled = false;
    if (Ti.Platform.name === 'android')
    { 
        audioPlayer.release();
    }   
}
else
{
    audioPlayer.start();
    pauseResumeButton.enabled = true;
}
 });

的另一个选择是:使用Titanium.Media.VideoPlayer将url传递给它,您将从远程文件的视频播放器(.mp3)获得持续时间,并在音频播放器中使用它.

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9749002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档