zoukankan      html  css  js  c++  java
  • 安卓原生 VideoView实现rtsp流媒体的播放

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

  • 相关阅读:
    PPK提供的浏览器类型及版本检测方法
    从KPI到OKR,高阶产品人如何推动业务高速增长
    线上流量越发昂贵,如何通过裂变营销实现业务增长?
    快速了解云原生架构
    阿里巴巴超大规模中台型团队研发提效实践
    如何通过数据智能玩转私域流量新生态
    Serverless Kubernetes:理想,现实与未来
    这只猫在云端定居了?边缘计算在天猫精灵云应用上的落地实践
    阿里毕玄:提升代码能力的4段经历
    你女朋友在买买买时,程序员小哥在干嘛?
  • 原文地址:https://www.cnblogs.com/javalinux/p/14549504.html
Copyright © 2011-2022 走看看