简体   繁体   English

Android Live Video Stream无法播放

[英]Android Live Video Stream Not Playing

I am trying to stream a live feed in rtsp as such: 我试图像这样在rtsp中流式传输实时供稿:

                       String uri = "rtsp://54.213.167.253:5544/63a1203d-4e12-438e-86ec-f447fa90cfd7";
                       Uri uri_add = Uri.withAppendedPath(MediaStore.Video.Media.INTERNAL_CONTENT_URI, "1");
                       videoView.setVideoURI(uri_add.parse(uri));
                       mediaController = new MediaController(_context);
                       videoView.setMediaController(mediaController);
                       videoView.requestFocus();
                       videoView.start();

This works on an HTC, Sony, and LG device that I have tested with, however does not work on the Galaxy S6 or any Samsung device. 此功能可在我测试过的HTC,Sony和LG设备上使用,但不适用于Galaxy S6或任何三星设备。 I have researched the encoding compatibilities and h.264 is what my stream is encoded, which should work on all the devices I have. 我已经研究了编码兼容性,并且h.264是我的流进行编码的对象,它应该可以在我拥有的所有设备上正常工作。 I am running Android v. 5.0.2 and 5.1.1 on these devices and there is no correlation between software to the issue. 我在这些设备上运行的是Android v。5.0.2和5.1.1,并且软件与该问题之间没有关联。 That is to say, the GalaxyS6 running 5.0.2 is not playing video while a HTC running 5.0.2 is playing video. 也就是说,运行5.0.2的GalaxyS6不在播放视频,而运行5.0.2的HTC正在播放视频。 I am completely lost as to what could be the cause of the "Can't Play Video" message that I get. 我完全迷失了我收到的“无法播放视频”消息的原因。

I have read all the articles and posts people have about streaming live video and attempted to implement them in my code, however I run in to the same issue each time. 我已经阅读了人们关于直播视频的所有文章和帖子,并尝试在我的代码中实现它们,但是我每次都遇到相同的问题。 I am pretty sure there is nothing wrong with the code, else it would not work at all on any device. 我很确定代码没有任何问题,否则在任何设备上都将无法使用。 Anyone have any ideas what could be causing this and why? 任何人都有什么想法可能导致这种情况,为什么?

This problem seems to be common on a few Samsung devices. 在某些三星设备上,此问题似乎很常见。 Did you check what Logcat shows? 您检查了Logcat显示的内容吗?

I had the same problem with a Galaxy Tab 4, I ended up using Vitamio's library for video streaming. 我在Galaxy Tab 4上遇到了同样的问题,最终我还是使用Vitamio的视频流库。 It's not been supported for some time now, but pretty easy to use and for basic customization 暂时尚不支持它,但是非常易于使用和基本自定义

Use this class. 使用此类。 This is running on Samsung devices also. 这也在三星设备上运行。

private ProgressDialog progressDialog;
    VideoView videoView;
    private myAsync sync;

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

        String videourl = "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";
        videoView = (VideoView) findViewById(R.id.video_view);
        progressDialog = ProgressDialog.show(CustomizeProgressDialogActivity.this, "",
                "Buffering video...", true);
        progressDialog.setCancelable(false);
        // progressDialog.dismiss();
        MediaController mediaController = new MediaController(CustomizeProgressDialogActivity.this);
        mediaController.setAnchorView(videoView);

        Uri video = Uri.parse(videourl);// insert video url
        videoView.setMediaController(mediaController);

        videoView.setVideoURI(video);
        videoView.requestFocus();

        sync = new myAsync();
        sync.execute();
        // PlayVideo();
    }


    private class myAsync extends AsyncTask<Void, Integer, Void> {

        int duration = 0;
        int current = 0;

        @Override
        protected Void doInBackground(Void... params) {

            videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

                public void onPrepared(MediaPlayer mp) {
                    progressDialog.dismiss();
                    videoView.start();
                    duration = videoView.getDuration();
                }
            });

            do {


                current = videoView.getCurrentPosition();
                System.out.println("duration - " + duration + " current- "
                        + current);



                if (sync.isCancelled())
                    break;

            }

            while (current != duration || current == 0);

            return null;
        }

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM