【发布时间】:2012-03-14 04:36:28
【问题描述】:
伙计们,我可以使用 Mediaplayer 播放音频文件。但我需要在特定时间播放音频文件。
例如:将 audio1.mp3 播放到 5 分钟。 音频文件只有 10 秒。但它应该一直播放到 5 分钟。
【问题讨论】:
标签: android media-player soundpool
伙计们,我可以使用 Mediaplayer 播放音频文件。但我需要在特定时间播放音频文件。
例如:将 audio1.mp3 播放到 5 分钟。 音频文件只有 10 秒。但它应该一直播放到 5 分钟。
【问题讨论】:
标签: android media-player soundpool
试试这个
mediaplayerplayer.setLooping(true);<--- this lets the audio to loop...
这是倒计时
MyCount counter;
Long s1;
counter= new MyCount(300000,1000);
counter.start();
public void asdf(View v){ <---- method for onclick of buttons pause and resuming timer
switch(v.getId()){
case R.id.button1:<-- for pause
counter.cancel();
break;
case R.id.button2:<--- for resume
counter= new MyCount(s1,1000);
counter.start();
}
}
public class MyCount extends CountDownTimer {
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
mediaplayer.stop();
mediaplayer.release();
}
@Override
public void onTick(long millisUntilFinished) {
s1=millisUntilFinished;
}
}
这还可以帮助您暂停媒体播放器...以及计时器...并让您将歌曲播放完整 5 分钟
【讨论】:
//decleration
MediaPlayer mp;
//specify the path of media file
String filepath="?";
//onCreate
mp=new MediaPlayer();
Uri myUri = Uri.parse(filepath);
mp.setLooping(true);
mp = MediaPlayer.create(ActivityName.this, myUri);
mp.start();
new CountDownTimer(300000,1000) {
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
if(mp.isPlaying())
{
mp.stop();
}
}
}.start();
【讨论】: