无法在android中使用videoview播放rtsp

2023-12-14

我已经使用 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 实际上只支持 mpeg 4 编码的基线配置文件,且 MOOV 原子设置正确。较新的设备支持其他方法(HLS 和更高规格的 mpeg4 类型),但并非所有设备都能以这种方式工作。您的 rtsp 流必须使用基线配置文件进行编码。

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

以下是有关 Android 和支持媒体的更明确信息:http://developer.android.com/guide/appendix/media-formats.html#recommendations

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在android中使用videoview播放rtsp 的相关文章

随机推荐