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