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

更多相关文章

  1. android应用安全——代码安全(android代码混淆)
  2. Android Studio如何设置代码自动提示
  3. 在Android中用纯Java代码布局
  4. 使用Android Studio调试Android Framework代码
  5. Android系列教程之六:TextView小组件的使用--附带超链接和跑马灯
  6. Linux手机打电话代码分析
  7. Android TextView设置自动识别的超链接字体颜色,及自身点击事件无

随机推荐

  1. android studio 弹窗中文乱码
  2. 【Demo 0002】Android 提醒框
  3. Android WebView相关知识(全)
  4. Android(集成baidu地图时)错误解决
  5. 【Android】用于打开各种文件的intent
  6. android等比例缩放图片
  7. Android(安卓)NDK使用Iconv进行编码转换
  8. Android(安卓)判断一个url是否有效
  9. Android Studio开发调试Installation fai
  10. android 手机利用重力感应摇晃 换歌曲 “