我可以使用Mediaplayer播放音频文件。但我需要在特定时间播放音频文件。
例如:播放audio1.mp3直到5分钟。 音频文件只有10秒钟。但它应该一直播放到5分钟。
答案 0 :(得分:2)
试试这个
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分钟的歌曲
答案 1 :(得分:0)
//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();