当前位置:   article > 正文

android播放rtsp文件_android exoplayer rtsp格式

android exoplayer rtsp格式

         最近尝试在android上播放rtsp实时流,最初的思路是:因为自己以前知道android 高版本支持rtsp协议,故打算用android自带的mediaPlayer看看效果,结果才发现这种方式只能播放rtsp流文件,不能播放实时流,实质与知道网络的url,播放网络视频类似。

          虽然暂时对自己无用,但还是记录下来,方便以后使用,关键代码如下

  1. import android.app.Activity;
  2. import android.net.Uri;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.Button;
  6. import android.widget.EditText;
  7. import android.widget.VideoView;
  8. public class TestRTSP extends Activity{
  9. private EditText etURL;
  10. private Button play,pause,stop;
  11. private VideoView mVideoView;
  12. public void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.main);
  15. etURL = (EditText)findViewById(R.id.URL);
  16. play = (Button)findViewById(R.id.play);
  17. pause = (Button)findViewById(R.id.pause);
  18. stop = (Button)findViewById(R.id.stop);
  19. play.setOnClickListener(new Button.OnClickListener(){
  20. public void onClick(View v) {
  21. PlayRtspStream(etURL.getEditableText().toString());
  22. }
  23. });
  24. mVideoView = (VideoView)this.findViewById(R.id.VideoViewDisplay);
  25. }
  26. //play rtsp stream
  27. private void PlayRtspStream(String rtspUrl){
  28. mVideoView.setVideoURI(Uri.parse(rtspUrl));
  29. mVideoView.requestFocus();
  30. mVideoView.start();
  31. }
  32. }
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3. android:id="@+id/widget32"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. android:orientation="vertical"
  7. xmlns:android="http://schemas.android.com/apk/res/android"
  8. >
  9. <EditText
  10. android:id="@+id/URL"
  11. android:hint="请输入rtsp url"
  12. android:layout_width="300px"
  13. android:layout_height="50px"
  14. >
  15. </EditText>
  16. <Button
  17. android:id="@+id/play"
  18. android:layout_width="wrap_content"
  19. android:layout_height="50px"
  20. android:text="播放"
  21. >
  22. </Button>
  23. <Button android:layout_width="wrap_content"
  24. android:id="@+id/pause" android:layout_height="50px"
  25. android:text="暂停"></Button>
  26. <Button
  27. android:id="@+id/stop"
  28. android:layout_width="wrap_content"
  29. android:layout_height="50px"
  30. android:text="停止"
  31. >
  32. </Button>
  33. <VideoView android:id="@+id/VideoViewDisplay"
  34. android:layout_width="352px"
  35. android:layout_height="288px">
  36. </VideoView>
  37. </LinearLayout>


            在知道这种方式不可行以后,故把目光放在vlc for android这个代码上,网上有vlc for android编译好的源代码,故考虑从其中提取自己想要的代码。等自己有空的时候分析下vlc for android 源码

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/852513
推荐阅读
相关标签
  

闽ICP备14008679号