本项目实现安卓原生 VideoView实现rtsp流媒体的播放。
AndroidManifest.xml权限设置
<uses-permission android:name=”android.permission.INTERNET”/>
 
activity_main.xml
<?xml version=”1.0″ encoding=”utf-8″?>
<android.support.constraint.ConstraintLayout xmlns:android=”http://schemas.android.com/apk/res/android”
 xmlns:app=”http://schemas.android.com/apk/res-auto”
 xmlns:tools=”http://schemas.android.com/tools”
 android:layout_width=”match_parent”
 android:layout_height=”match_parent”
 tools:context=”.MainActivity”>
 <VideoView
 android:layout_width=”match_parent”
 android:layout_height=”match_parent”
 android:id=”@+id/videoView”
 />
</android.support.constraint.ConstraintLayout> 
MainActivity
package com.example.apple.app1;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
public class MainActivity extends Activity implements View.OnTouchListener {
 private VideoView videoView;
 private String uri=”rtsp://192.168.123.47/a.mkv”;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);//导入一个布局
 videoView = (VideoView) findViewById(R.id.videoView);
 //findViewById()获取在布局中定义了的元素,返回的是一个View对象,需要向下转型
 MediaController mediaController = new MediaController(this);
 videoView.setVideoURI(Uri.parse(uri));
 videoView.setMediaController(mediaController);
 videoView.start();
 videoView.setOnTouchListener(this);
 }
 @Override
 protected void onDestroy() {
 super.onDestroy();
 if(videoView!=null){
 videoView.suspend();
 }
 }
 public boolean onTouch(View view, MotionEvent motionEvent) {//实现onTouch接口
 switch (view.getId()){
 case R.id.videoView:
 Toast.makeText(MainActivity.this,”ddd”,Toast.LENGTH_LONG).show();
 break;
 }
 return false;
 }
} 
————————————————
版权声明:本文为CSDN博主「编程圈子」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xundh/article/details/85218844