我有一個mp3文件,我想播放一個特定的單詞。我有一個開始時間(6889 ms
)和結束時間(7254 ms
)。Android:如何在播放特定毫秒時停止播放媒體(mp3)?
我有這些代碼:
package com.example.playword;
import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.widget.TextView;
public class PlayWord extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView tv = new TextView(this);
tv.setText("Playing...");
setContentView(tv);
final MediaPlayer mPlayer = MediaPlayer.create(this, R.raw.nicholas);
try {
mPlayer.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mPlayer.seekTo(6889); //this is the start time
mPlayer.start();
//how can I end it at 7254 ms?
}
}