赞
踩
最近尝试在android上播放rtsp实时流,最初的思路是:因为自己以前知道android 高版本支持rtsp协议,故打算用android自带的mediaPlayer看看效果,结果才发现这种方式只能播放rtsp流文件,不能播放实时流,实质与知道网络的url,播放网络视频类似。
虽然暂时对自己无用,但还是记录下来,方便以后使用,关键代码如下
- 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 TestRTSP extends Activity{
-
- private EditText etURL;
- private Button play,pause,stop;
- private VideoView mVideoView;
-
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
-
- etURL = (EditText)findViewById(R.id.URL);
- play = (Button)findViewById(R.id.play);
- pause = (Button)findViewById(R.id.pause);
- stop = (Button)findViewById(R.id.stop);
-
-
- play.setOnClickListener(new Button.OnClickListener(){
- public void onClick(View v) {
- PlayRtspStream(etURL.getEditableText().toString());
- }
- });
-
- mVideoView = (VideoView)this.findViewById(R.id.VideoViewDisplay);
-
- }
-
- //play rtsp stream
- private void PlayRtspStream(String rtspUrl){
- mVideoView.setVideoURI(Uri.parse(rtspUrl));
- mVideoView.requestFocus();
- mVideoView.start();
- }
- }
-
-
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- android:id="@+id/widget32"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical"
- xmlns:android="http://schemas.android.com/apk/res/android"
- >
- <EditText
- android:id="@+id/URL"
- android:hint="请输入rtsp url"
- android:layout_width="300px"
- android:layout_height="50px"
- >
- </EditText>
- <Button
- android:id="@+id/play"
- android:layout_width="wrap_content"
- android:layout_height="50px"
- android:text="播放"
- >
- </Button>
-
- <Button android:layout_width="wrap_content"
- android:id="@+id/pause" android:layout_height="50px"
- android:text="暂停"></Button>
-
- <Button
- android:id="@+id/stop"
- android:layout_width="wrap_content"
- android:layout_height="50px"
- android:text="停止"
- >
- </Button>
- <VideoView android:id="@+id/VideoViewDisplay"
- android:layout_width="352px"
- android:layout_height="288px">
- </VideoView>
-
-
- </LinearLayout>
在知道这种方式不可行以后,故把目光放在vlc for android这个代码上,网上有vlc for android编译好的源代码,故考虑从其中提取自己想要的代码。等自己有空的时候分析下vlc for android 源码
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。