寻求在我的代码中无法正常工作,
我只能在我的文件的前半部分找到,
我在{30分钟,60分钟,90分钟,120分钟}测试了mp3并且无法正常工作,但是使用mp4可以。
public class Player extends AsyncTask<Integer, Integer, Integer> implements
OnBufferingUpdateListener, OnCompletionListener, OnErrorListener {
private static MediaPlayer mp;
protected static Player PLAYER = null;
public Player(){
mp = Defined.mp;
mp.setOnBufferingUpdateListener(this);
mp.setOnCompletionListener(this);
mp.setOnErrorListener(this);
}
doInBackground:
@Override
protected Integer doInBackground(Integer... params) {
prepareFileToPlay();
mp.start();
startProgress();
return null;
}
准备文件:
protected void prepareFileToPlay(){
String url="http://192.168.1.2/test10.mp3"; //mp3 duration: 60min
mp.reset();
try {
mp.setDataSource(url);
mp.prepare();
publishProgress(PLAYING);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
播放功能:
public static void play(){
if(PLAYER != null) PLAYER.cancel(true);
PLAYER = new Player();
PLAYER.execute("");
}
寻求功能:
public static void seekTo(int time){
//mp.seekTo(time);
//mp.seekTo(mp.getDuration()-10000); //seekTo 59:50
//mp.seekTo(mp.getDuration()-60000); //seekTo 59:00
Log.v("player", "CurrentPosition: "+ mp.getCurrentPosition() + " Duration:"+ mp.getDuration()); //Duration: 60 min
}