2012-03-17 10 views

答えて

0

EDITED

あなたはプログレスバーを表示したい場合、あなたはあなたのmp3ファイルの合計時間を必要としています。しかし、現在のチタニウム1.8 SDKでは、の合計の継続時間はから、リモート・ファイル(.mp3)のオーディオ・プレーヤーにはなりません。しかし、それでも、バックエンド側から合計期間を得ることができます。同様に、あなたの応答に総継続時間タグを設定し、進捗の最大サイズで使用します。

//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

'var audioPlayer = Ti.Media.createAudioPlayer({ url: 'http://naturalimprove.com/mp3/Drone.mp3'、 allowBackground:true }); 上記の作成されたオーディオ!!! –

+0

@MathewOrleans:更新された回答を確認... – Maulik

関連する問題