Android rtsp流视频 播放

之前用的是 vitamio 为了播放flv格式的流视频,但是却播不了rtsp格式的流视频,于是上网扒了半天,各有各的方法,试完发现都不很行,还好再gitbub上找到了一个专门做rtsp的开源产品

附上链接 https://github.com/NodeMedia/NodeMediaClient-Android

附上demo地址 https://github.com/NodeMedia/QLive-Android

文档地址 https://github.com/NodeMedia/NodeMediaClient-Android/blob/2.x/docs/NodePlayer_API_CN.md

流程很简单,使用很方便

记录一下 :

studio 导包

项目gradle中

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

app gradle 中

dependencies {
    compile 'com.github.NodeMedia:NodeMediaClient-Android:2.7.2'
}

xml文件附上:

<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".Main2Activity">

    <cn.nodemedia.NodePlayerView
        android:id="@+id/nodePlayer"
        android:layout_width="match_parent"
        android:layout_height="250dp" />

</LinearLayout>

主要代码:

public class Main2Activity extends AppCompatActivity {

    private NodePlayerView nodePlayerView;
    private NodePlayer nodePlayer;
   
    String url2 = "换成你的url";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        nodePlayerView =findViewById(R.id.nodePlayer);
        //设置渲染器类型
        nodePlayerView.setRenderType(NodePlayerView.RenderType.SURFACEVIEW); 
        //设置视频画面缩放模式
        nodePlayerView.setUIViewContentMode(NodePlayerView.UIViewContentMode.ScaleToFill);

        nodePlayer =new NodePlayer(this);
        //设置播放视图
        nodePlayer.setPlayerView(nodePlayerView);
        //设置RTSP流使用的传输协议,支持的模式有: 
        nodePlayer.setRtspTransport(NodePlayer.RTSP_TRANSPORT_TCP);
        nodePlayer.setInputUrl(url2);
        //设置视频是否开启
        nodePlayer.setVideoEnable(true);
        nodePlayer.start();
    }
}

 注意:setRtspTransport 这个方法,每个人的传输协议不同 ,根据自己情况修改,不设置可能不会显示

 其他 根据个人情况进行设置,文档,代码都已经附上链接,好好阅读,定能成功

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 14
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值