【发布时间】:2014-04-29 00:38:14
【问题描述】:
搜索在我的代码中无法正常工作,
我只能在前半部分文件中准确查找,
我在 {30min, 60min, 90min, 120min} 中使用 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
}
【问题讨论】:
标签: android android-asynctask android-mediaplayer seek