android MediaPlayer setDataSource:IOException错误

时间:2016-10-11 11:22:00

标签: java android

我有一个m3u8链接,可以在vlc上正常工作,但是在使用mediaPlayer for android并传递m3u8 url链接时出现了这个错误:

错误:

setDataSource: IOException! uri=http://46.166.162.35:9090/load/b0922f3fa8aa/35.m3u8
 error (1, -2147483648)
Prepare failed.: status=0x1

我也遇到了这个MediaPlayer.setDataSource(String) not working with local files,但未能解决。我不知道我在哪里做错了。看看。

这是我的代码。

  String URL="http://46.166.162.35:9090/load/b0922f3fa8aa/35.m3u8";//ss1
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video);
    view = (VideoView)findViewById(R.id.videoView1);
    pd = new ProgressDialog(Show340.this);

    pd.setTitle("Video Streaming....");
    pd.setMessage("Buffering..");
    pd.setIndeterminate(false);
    pd.setCancelable(false);
    pd.show();

    try{
        MediaController controller = new MediaController(Show340.this);
        MediaPlayer mp = new MediaPlayer();
        controller.setAnchorView(view);
        Uri vid = Uri.parse(URL);
        mp.setDataSource(Show340.this,vid);
        mp.prepare();
        mp.start();
    /*  Uri vid = Uri.parse(URL);*/
        view.setMediaController(controller);
        view.setVideoURI(vid);
        mp.release();
    }catch(Exception e){
        Log.e("Error",e.getMessage());
        e.printStackTrace();


    }
    view.requestFocus();
    view.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        public void onPrepared(MediaPlayer mp) {
            // TODO Auto-generated method stub
            pd.dismiss();
            view.start();

        }
    });
    view.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
            // TODO Auto-generated method stub
            if(pd.isShowing()){
                pd.dismiss();
            }
            finish();
        }
    });
}

0 个答案:

没有答案