Play RTSP streaming in an Android application

左心房为你撑大大i 提交于 2019-11-26 09:28:34

问题


I am trying to develop an Android based application, which can play video from a live stream. This live stream is produced using Wowza Media Server.

The URL is:

rtsp://tv.hindiworldtv.com:1935/live/getpun

I have tried following code in ecliplse:

package com.kalloh.wpa;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.widget.MediaController;
import android.widget.VideoView;


public class a extends Activity {

    VideoView videoView;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        //Create a VideoView widget in the layout file
        //use setContentView method to set content of the activity to the layout file which contains videoView
        this.setContentView(R.layout.videoplayer);

        videoView = (VideoView)this.findViewById(R.id.videoView);

        //add controls to a MediaPlayer like play, pause.
        MediaController mc = new MediaController(this);
        videoView.setMediaController(mc);

        //Set the path of Video or URI
        videoView.setVideoURI(Uri.parse(\"rtsp://tv.hindiworldtv.com:1935/live/getpnj\"));
        //

        //Set the focus
        videoView.requestFocus();
    }
}

At first, it was not working.

Now it started working, but it stops after 20 to 30 seconds. How can I fix this problem?


回答1:


Using VideoView is a good solution, but we can also use the native player to play RTSP. This is an example:

if (movieurl.startsWith("rtsp://")) {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(movieurl));
    startActivity(intent);
}

Bear in mind your media must be created with Android Supported Media Formats (codecs).




回答2:


I also had the same problem in ICS 4.x. Also, you can check whether your stream URL is working properly or not.

Also check your code with this sample URL.




回答3:


I had the same problem with Galaxy Note N7000 (ICS 4.0.3) and VLC 2.0.2 - the video dies after 60 seconds. But when I turn to VLC media player 1.1.4, everything just works well!

So sometimes it depends on the media server. You can try RTSP from YouTube (go to m.youtube.com and then right click on some video -> copy location link -> that is the RTSP link you need).




回答4:


I found the solution. Transmission should be within the preferred setting by Android. For more details, see Supported Media Formats.



来源:https://stackoverflow.com/questions/11274906/play-rtsp-streaming-in-an-android-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!