【问题标题】:Unable to play rtsp using videoview in android无法在android中使用videoview播放rtsp
【发布时间】:2012-11-08 15:05:22
【问题描述】:

我已经使用 VLC 设置了 RTSP 服务器。然后我写了一个应用程序,这是我的代码:

package com.ashley.work;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.support.v4.app.NavUtils;
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 TestPlayRTSP extends Activity {

Button playButton ;  
VideoView videoView ;  

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_play_rtsp);

    videoView = (VideoView)this.findViewById(R.id.myvideoview);  

    playButton = (Button)this.findViewById(R.id.button1);  
    playButton.setOnClickListener(new Button.OnClickListener(){  
    public void onClick(View v) {  
    PlayRtspStream("rtsp://140.xxx.xxx.xxx:8554/");  
    }  
    });  


}

private void PlayRtspStream(String rtspUrl){  
    videoView.setVideoURI(Uri.parse(rtspUrl));  
    videoView.requestFocus();  
    videoView.start();  
}  

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_test_play_rtsp, menu);
    return true;
}

}

我已经设置了权限。但是这个还是不能玩。单击按钮后没有任何反应。但是,如果我将 rtsp 替换为其他这两个:

  1. rtsp://218.204.223.237:554/live/1/66251FC11353191F/e7ooqwcfbqjoo80j.sdp

  2. rtsp://v5.cache1.c.youtube.com/CjYLENy73wIaLQnhycnrJQ8qmRMYESARFEIJbXYtZ29vZ2xlSARSBXdhdGNoYPj_hYjnq6uUTQw=/0/0/0/video.3gp

应用程序将正常播放。谁能告诉我为什么?有没有办法播放VLC流???

谢谢

【问题讨论】:

    标签: android rtsp


    【解决方案1】:

    Android 仅支持正确设置 MOOV atom 的 mpeg 4 编码基线配置文件。较新的设备支持其他方法(HLS 和更高配置的 mpeg4 类型),但并非所有设备都能以这种方式工作。您的 rtsp 流必须使用基线配置文件进行编码。

    如果您在VLC 中打开您的 RTSP 流并打开您的网络流,然后打开媒体信息,您可以看到您的流用于音频和视频的编解码器

    这里是关于 android 和支持媒体的更权威信息:http://developer.android.com/guide/appendix/media-formats.html#recommendations

    【讨论】:

    • vedioview 支持的媒体是否与 MediaPlayer 相同?如果我尝试 MediaPlayer,结果会一样吗?谢谢!
    • "您的 rtsp 流必须使用基线配置文件进行编码" 我该怎么做?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-24
    相关资源
    最近更新 更多