Android VideoView如何播放RTSP的流

來源:互聯網
上載者:User

目前在做視頻應用的時候,比較先進的技術就是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的地址) 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.