【问题标题】:Can't seek mp3 more than 50% with MediaPlayer in AsyncTask在 AsyncTask 中使用 MediaPlayer 无法搜索超过 50% 的 mp3
【发布时间】: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


    【解决方案1】:

    我在BlueStacks 中检查我的应用程序,但我知道这个问题是专门针对 BlueStacks 的,这不是一个公共问题,它并不重要......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-21
      • 1970-01-01
      • 2021-03-16
      • 2015-07-25
      • 1970-01-01
      相关资源
      最近更新 更多