Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
438 views
in Technique[技术] by (71.8m points)

Play RTSP streaming in an Android application

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...