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 源码

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 14
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值