【问题标题】:How to Play RTSP Video in Android?如何在 Android 中播放 RTSP 视频?
【发布时间】:2012-10-02 22:57:10
【问题描述】:

我想在 VideoView 上播放 Youtube 视频。 我已经搜索了很多并发现 VideoView Support rtsp URL Video 。 但我收到错误消息:我的 android 设备是 2.3.5 & 使用 Wifi。 我的 VideoView 代码是:

  final VideoView videoView = (VideoView) findViewById(R.id.VideoView);
        Button youtube=(Button)findViewById(R.id.button1);
       final  MediaController mediaController = new MediaController(this);
        mediaController.setScrollBarStyle(DEFAULT_KEYS_DISABLE);
        mediaController.setPressed(true);
         mediaController.setAnchorView(videoView);
        Uri video = Uri.parse("rtsp://v3.cache7.c.youtube.com/CiILENy73wIaGQlOCTh0GvUeYRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp");
       // Uri video = Uri.parse(getUrlVideoRTSP("http://gdata.youtube.com/feeds/api/users/mashable/uploads?&v=2"));
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(video);
        videoView.requestFocus();
        videoView.start();

我的 LogCat 错误是:

10-12 11:56:50.369: D/WindowManagerImpl(6880): addView, new view, mViews[0]: com.android.internal.policy.impl.PhoneWindow$DecorView@4055c4e0

10-12 11:56:50.430: I/AudioSystem(6880): getting audio flinger

10-12 11:56:50.430: I/AudioSystem(6880): returning new audio session id

10-12 11:56:50.430: D/MediaPlayer(6880): setDataSource(Context context, rtsp://v3.cache7.c.youtube.com/CiILENy73wIaGQlOCTh0GvUeYRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp, Map<String, String> headers) in

10-12 11:56:50.460: I/MediaPlayer(6880): skip setting (httpproxyip,null)

10-12 11:56:50.460: I/MediaPlayer(6880): skip setting (httpproxyport,null)

10-12 11:56:50.460: I/MediaPlayer(6880): skip setting (rtspproxyip,null) 

10-12 11:56:50.460: I/MediaPlayer(6880): skip setting (rtspproxyport,null) 

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (minudpport,1024)

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (maxudpport,65535)

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (buffertime,7)

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (rtsptimeout,25000)

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (rtptimeout,25000)

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (rtcpreportinterval,3000)

10-12 11:56:50.460: I/MediaPlayer(6880): add setting (rtspkeepaliveinterval,35000)
10-12 11:56:50.460: D/MediaPlayer(6880): Couldn't open file on client side, trying server side

10-12 11:56:50.470: I/MediaPlayer(6880): disable CIQ

10-12 11:56:50.470: D/MediaPlayer(6880): setDataSource(Context context, rtsp://v3.cache7.c.youtube.com/CiILENy73wIaGQlOCTh0GvUeYRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp, Map<String, String> headers) out

10-12 11:57:20.589: W/MediaPlayer(6880): info/warning (34355, 3000)

10-12 11:57:20.589: I/MediaPlayer(6880): Info (34355,3000)

10-12 11:57:20.599: E/MediaPlayer(6880): error (1, -1003)

10-12 11:57:20.599: E/MediaPlayer(6880): Error (1,-1003)

10-12 11:57:20.599: D/VideoView(6880): Error: 1,-1003

【问题讨论】:

  • 您确定您的视频网址正确吗?
  • 我认为你的网址不对..
  • 先生,我使用了 Json 的 url。我检查了不同的网址。但问题是这样。网址是:-gdata.youtube.com/feeds/api/users/mashable/…
  • 看看我的回答,任何有关这方面的帮助告诉我。

标签: android video android-videoview rtsp youtube-channels


【解决方案1】:

首先,您必须从您的 YouTube 频道获取视频。因为下面这个例子会对你有所帮助。

See My answer Here. 它会给你一个完美的想法。

另外,要在 videoview 中播放视频,您需要 rtsp 格式的视频。

您可以将您的网址转换为 rtsp 格式,我为 HERE. 创建函数

【讨论】:

  • 我已经使用了您的代码,它在 rtsp 中从 http 的转换仍然无法播放。同样的错误...
  • @DeepankerChaudhary 你得到解决方案了吗?
  • 不!我可以通过 Intent 在 webview 上播放视频但要求是我将显示两个按钮上一个和下一个所以我想在 VideoView 上播放视频。出了点问题可能是移动支持问题。
【解决方案2】:

通过使用这种方式,我在 android 中播放 rtsp 视频。

    videourl="rtsp://..........";
    videoView = (VideoView) findViewById(R.id.video_View);
    progressDialog = ProgressDialog.show(Video.this, "",
            "Buffering video...", true);
    progressDialog.setCancelable(false);
    // progressDialog.dismiss();
    MediaController mediaController = new MediaController(Video.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 OnPreparedListener() {

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

        do {


            current = videoView.getCurrentPosition();
            System.out.println("duration - " + duration + " current- "
                    + current);
            /*if(current/600==0)
            {
                //sync.cancel(true);

                videoView.pause();
                try {
                    wait(300000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();q
                }

                videoView.resume();

                videoView.seekTo(current);
            }*/


        }

            if (sync.isCancelled())
                break;

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

        return null;
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-24
    相关资源
    最近更新 更多