[英]play mp3 files at designated duration
I'm trying to make an app that can play mp3 files at designated duration through MediaPlayer 我正在尝试制作一个可以通过MediaPlayer在指定时间播放mp3文件的应用
for example: 例如:
Start Time: 00:42 开始时间: 00 : 42
End Time: 01:23 结束时间:01:23
my question is: 我的问题是:
-is it possible to designate the start and end time via textview at MM:SS format? -是否可以通过textview以MM:SS格式指定开始时间和结束时间?
Thanks!! 谢谢!!
Yes after initiating the MediaPlayer and loading the file , you can pause or stop the player after using specific time 是的,在启动MediaPlayer并加载文件后,可以在指定时间后暂停或停止播放器
while(mPlayer.isPlaying()) {
if(mPlayer.getCurrentPosition() > 7254 && mPlayer.getCurrentPosition() < 7410 ){
labelTxt.setText("Stop: " + mPlayer.getCurrentPosition() );
mPlayer.stop();
break;
}
}
use This code 使用此代码
MediaPlayer mp;
Runnable stopPlayerTask = new Runnable(){
@Override
public void run() {
mp.pause();
}};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText etStartTime = (EditText)findViewById(R.id.edittext_start_time);
EditText etEndTime = (EditText)findViewById(R.id.edittext_end_time);
String StartTime = etStartTime.getText().toString();
String EndTime = etEndTime.getText().toString();
long min = Integer.parseInt(StartTime .substring(0, 2));
long sec = Integer.parseInt(StartTime .substring(3));
long minEnd = Integer.parseInt(StartTime .substring(0, 2));
long secEnd = Integer.parseInt(StartTime .substring(3));
long startLong = (min * 60L) + sec;
long endLong = (minEnd * 60) + secEnd;
int starIntTime = (int) startLong;
int endIntTime = (int) endLong;
mp = MediaPlayer.create(this, R.raw.my_sound_file);
mp.seekTo(starIntTime);
mp.start();
Handler handler = new Handler();
handler.postDelayed(stopPlayerTask, endIntTime);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.