android播放rtsp文件
16lz
2021-01-23
最近尝试在android上播放rtsp实时流,最初的思路是:因为自己以前知道android 高版本支持rtsp协议,故打算用android自带的mediaPlayer看看效果,结果才发现这种方式只能播放rtsp流文件,不能播放实时流,实质与知道网络的url,播放网络视频类似。
虽然暂时对自己无用,但还是记录下来,方便以后使用,关键代码如下
import android.app.Activity;import android.net.Uri;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.VideoView;public class TestRTSP extends Activity{ private EditText etURL; private Button play,pause,stop; private VideoView mVideoView; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); etURL = (EditText)findViewById(R.id.URL); play = (Button)findViewById(R.id.play); pause = (Button)findViewById(R.id.pause); stop = (Button)findViewById(R.id.stop); play.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v) { PlayRtspStream(etURL.getEditableText().toString()); } }); mVideoView = (VideoView)this.findViewById(R.id.VideoViewDisplay); } //play rtsp stream private void PlayRtspStream(String rtspUrl){ mVideoView.setVideoURI(Uri.parse(rtspUrl)); mVideoView.requestFocus(); mVideoView.start(); }}
<?xml version="1.0" encoding="utf-8"?><LinearLayoutandroid:id="@+id/widget32"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"xmlns:android="http://schemas.android.com/apk/res/android"><EditTextandroid:id="@+id/URL"android:hint="请输入rtsp url"android:layout_width="300px"android:layout_height="50px"></EditText><Buttonandroid:id="@+id/play"android:layout_width="wrap_content"android:layout_height="50px"android:text="播放"></Button><Button android:layout_width="wrap_content" android:id="@+id/pause" android:layout_height="50px" android:text="暂停"></Button><Buttonandroid:id="@+id/stop"android:layout_width="wrap_content"android:layout_height="50px"android:text="停止"></Button><VideoView android:id="@+id/VideoViewDisplay" android:layout_width="352px" android:layout_height="288px"></VideoView></LinearLayout>
在知道这种方式不可行以后,故把目光放在vlc for android这个代码上,网上有vlc for android编译好的源代码,故考虑从其中提取自己想要的代码。等自己有空的时候分析下vlc for android 源码
更多相关文章
- android 7种网络连接方式《IT蓝豹》
- Android学习笔记(二) 布局方式的介绍
- Android 网络编程之网络通信几种方式实例分享
- Android Handler 异步消息处理机制 《第一行代码》
- Anbox:在 Linux 上运行 Android 应用程序的简单方式 | Linux 中国
- Android启动界面优化技巧-Splash Screens的正确方式
- Android的两种数据存储方式分析(二)
- Android Studio NDK开发在C代码中将Log输出到logcat上面
- 22个值得收藏的android开源代码-UI篇