通过流媒体播放视频时出错

时间:2016-08-22 19:16:46

标签: android video-streaming android-videoview

我有以下代码,我试图通过流媒体播放视频,这会返回此错误。 互联网许可是可以的。 并且服务器上视频的路径没问题。

  

W / MediaPlayer:无法在客户端打开文件;尝试服务器端:   java.io.FileNotFoundException:没有内容   提供商:" http://myserver.com.br/teste.m3u8"

     

D / VideoView:错误:1,-2147483648

     

E / MediaPlayer:错误(1,-2147483648)

public class Main2Activity extends AppCompatActivity {

    private String urlVideo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        initVideo();
    }

    private void initVideo() {

        final VideoView vidView = (VideoView) findViewById(R.id.videoview);
        MediaController vidControl = new MediaController(this);
        vidControl.setAnchorView(vidView);
        vidView.setMediaController(vidControl);

        urlVideo = getIntent().getStringExtra("url");

        if (urlVideo != null) {

            try {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        vidView.setVideoURI(Uri.parse(urlVideo));

                        vidView.requestFocus();

                        vidView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                            @Override
                            public void onPrepared(MediaPlayer mp) {
                                mp.start();
                            }
                        });

                        vidView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
                            @Override
                            public boolean onError(MediaPlayer mp, int what, int extra) {
                                showAlertError(String.valueOf(what), String.valueOf(extra));
                                return false;
                            }
                        });
                    }
                });

            } catch (Exception e) {
                showAlertError(e.toString());
            }
        }

    }

    private void showAlertError(String... error) {

        final StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("Video Play Error :").append(error[0]);

        if (error[1] != null) {
            stringBuilder.append(", ").append(error[1]);
        }

        AlertDialog alert = new AlertDialog.Builder(this).setTitle(getString(R.string.INIT_ERROR))
                .setMessage(getString(R.string.video_error))
                .setCancelable(false)
                .setPositiveButton(android.R.string.ok,
                        new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                System.out.println(stringBuilder.toString());
                                dialog.dismiss();
                                Main2Activity.this.finish();
                            }
                        }).create();

        alert.show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
}

0 个答案:

没有答案