android 播放rtsp协议流媒体
16lz
2021-01-23
目前在做视频应用的时候,比较先进的技术就是RTSP流媒体了,那么如和利用Android的播放控件VideoView来播放RTSP的流呢?
RTSP流媒体链接:
http://218.204.223.237:8081/wap/
这个链接含有所有的RTSP流媒体的链接,现在咱们就用VideoView来播放里面的RTSP的流,咱们以其中的一个链接来测试下好了:
rtsp://218.204.223.237:554/live/1/66251FC11353191F/e7ooqwcfbqjoo80j.sdp.
效果截图:
核心代码如下:
- package com.video.rtsp;
- 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 rtspActivity extends Activity {
- /** Called when the activity is first created. */
- Button playButton ;
- VideoView videoView ;
- EditText rtspUrl ;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- rtspUrl = (EditText)this.findViewById(R.id.url);
- playButton = (Button)this.findViewById(R.id.start_play);
- playButton.setOnClickListener(new Button.OnClickListener(){
- public void onClick(View v) {
- PlayRtspStream(rtspUrl.getEditableText().toString());
- }
- });
- videoView = (VideoView)this.findViewById(R.id.rtsp_player);
- }
- //play rtsp stream
- private void PlayRtspStream(String rtspUrl){
- videoView.setVideoURI(Uri.parse(rtspUrl));
- videoView.requestFocus();
- videoView.start();
- }
- }
在点击开始播放后,一般要等个10几秒中才开始播放的,直接的设置需要播放的RTSP的地址:setVideoURI(rtsp的地址)
更多相关文章
- android应用安全——代码安全(android代码混淆)
- Android Studio如何设置代码自动提示
- 在Android中用纯Java代码布局
- 使用Android Studio调试Android Framework代码
- Android系列教程之六:TextView小组件的使用--附带超链接和跑马灯
- Linux手机打电话代码分析
- Android TextView设置自动识别的超链接字体颜色,及自身点击事件无