android RTSP流媒体播放

时间:2021-06-11 05:48:06
package com.example.internetvideo;


import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.net.Uri;  
import android.os.Environment;  
import android.widget.MediaController;  
import android.widget.VideoView; 
public class MainActivity extends ActionBarActivity {


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


          
        Uri uri = Uri.parse("rtsp://v2.cache2.c.youtube.com/CjgLENy73wIaLwm3JbT_%ED%AF%80%ED%B0%819HqWohMYESARFEIJbXYtZ29vZ2xlSARSB3Jlc3VsdHNg_vSmsbeSyd5JDA==/0/0/0/video.3gp");  
        VideoView videoView = (VideoView)this.findViewById(R.id.video_frame);  
        videoView.setMediaController(new MediaController(this));  
        videoView.setVideoURI(uri);  
        //videoView.start();  
        videoView.requestFocus(); 
    }

}


 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal">
    <VideoView
            android:id="@+id/video_frame"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"/>  
</RelativeLayout>