android播放rtsp文件

         最近嘗試在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 源碼

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章