`

Android VideoView如何播放RTSP的流

阅读更多
目前在做视频应用的时候,比较先进的技术就是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的地址)

转自:http://www.shouyanwang.org/thread-96-1-1.html
  • 大小: 201.7 KB
分享到:
评论
7 楼 u012094586 2014-06-12  

这个代码是不是不全呀,能不能提供完整版的给予参考呢?xiexie
6 楼 ron.luo 2013-05-21  
不错,挺惊讶的,哈哈,学习饿了》。。
5 楼 abccna 2012-10-17  
在Jellybean上运行了一下这个rtsp客户端,不能播放。
主要有以下几个问题:
1. attribute must be localized error
res: layout/main.xml中不能直接写具体的字符串,也要使用android:text="@string/xxx"
2. 指定sdk version,这样就可以在jellybean的手机上安装
3. 增加user permission android.permission.INTERNET, 这样apk就由权限访问rtsp server
解决上述三个问题以后,就可以在jellybean上运行了。
4 楼 lonpo 2012-03-18  
这个地址提供了rtsp流媒体非常好,但是这个流媒体服务器是用什么搭建的呢?如何搭建呢?
3 楼 bluskywheat 2012-02-29  
请问这个网址提供的rtsp流媒体是H264格式的吗?期待您的答复,谢谢啦
2 楼 bluskywheat 2012-02-29  
Very good!Thanks!
1 楼 求知者long 2011-10-14  
   试试先!

相关推荐

Global site tag (gtag.js) - Google Analytics