本项目实现安卓原生 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:andro
/>
</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

相关文章:

  • 2022-02-20
  • 2022-12-23
  • 2021-12-06
  • 2021-12-01
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-03
  • 2021-12-07
  • 2022-12-23
  • 2021-06-10
  • 2021-04-04
  • 2022-12-23
相关资源
相似解决方案