`
zhangyf1987hb
  • 浏览: 80471 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

android 播放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. 

效果截图: 

 

核心代码如下: 

Java代码  收藏代码
  1. package com.video.rtsp;  
  2.   
  3. import android.app.Activity;  
  4. import android.net.Uri;  
  5. import android.os.Bundle;  
  6. import android.view.View;  
  7. import android.widget.Button;  
  8. import android.widget.EditText;  
  9. import android.widget.VideoView;  
  10.   
  11. public class rtspActivity extends Activity {  
  12. /** Called when the activity is first created. */  
  13.   
  14. Button playButton ;  
  15. VideoView videoView ;  
  16. EditText rtspUrl ;  
  17.   
  18. @Override  
  19. public void onCreate(Bundle savedInstanceState) {  
  20. super.onCreate(savedInstanceState);  
  21. setContentView(R.layout.main);  
  22.   
  23. rtspUrl = (EditText)this.findViewById(R.id.url);  
  24. playButton = (Button)this.findViewById(R.id.start_play);  
  25. playButton.setOnClickListener(new Button.OnClickListener(){  
  26. public void onClick(View v) {  
  27. PlayRtspStream(rtspUrl.getEditableText().toString());  
  28. }  
  29. });  
  30.   
  31. videoView = (VideoView)this.findViewById(R.id.rtsp_player);  
  32.   
  33. }  
  34.   
  35. //play rtsp stream  
  36. private void PlayRtspStream(String rtspUrl){  
  37. videoView.setVideoURI(Uri.parse(rtspUrl));  
  38. videoView.requestFocus();  
  39. videoView.start();  
  40. }  
  41.   
  42. }  



在点击开始播放后,一般要等个10几秒中才开始播放的,直接的设置需要播放的RTSP的地址:setVideoURI(rtsp的地址)

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics