目前在做视频应用的时候,比较先进的技术就是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的地址)
VideoViewRtsp.rar (23.4 KB, 下载次数: 1223) |