我一直在开发一个Android应用程序,可以通过RTSP显示实时流媒体视频。假设我有一个运行良好的RTSP服务器,它传递h264数据包,要查看流,我们应该连接到rtsp://1.2.3.4:5555/stream
所以我尝试使用原生的MediaPlayer\VideoView,但没有运气(视频在播放2-3秒后就卡住了,所以我加载了mrmaffen的vlc-android-sdk (可以在here中找到),并使用了以下代码:
ArrayList<String> options = new ArrayList<String>();
options.add("--no-drop-late-frames");
options.add("--no-skip-frames");
options.add("-vvv");
videoVlc = new LibVLC(options);
newVideoMediaPlayer = new org.videolan.libvlc.MediaPlayer(videoVlc);
final IVLCVout vOut = newVideoMediaPlayer.getVLCVout();
vOut.addCallback(this);
vOut.setVideoView(videoView); //videoView is a pre-defined view which is part of the layout
vOut.attachViews();
newVideoMediaPlayer.setEventListener(this);
Media videoMedia = new Media (videoVlc, Uri.parse(mVideoPath));
newVideoMediaPlayer.setMedia(videoMedia);
newVideoMediaPlayer.play();问题是我看到一个空白屏幕。
请记住,当我把一个RTSP链接只与音频流,它工作得很好。
有没有人熟悉这个sdk,并对这个问题有所了解?提前感谢
发布于 2017-03-08 19:52:56
尝试添加此选项:
--rtsp-tcp发布于 2016-01-11 11:31:10
我用以下代码播放rtsp流
try {
Uri rtspUri=Uri.parse("rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov");
final MediaWrapper mw = new MediaWrapper(rtspUri);
mw.removeFlags(MediaWrapper.MEDIA_FORCE_AUDIO);
mw.addFlags(MediaWrapper.MEDIA_VIDEO);
MediaWrapperListPlayer.getInstance().getMediaList().add(mw);
VLCInstance.getMainMediaPlayer().setEventListener(this);
VLCInstance.get().setOnHardwareAccelerationError(this);
final IVLCVout vlcVout = VLCInstance.getMainMediaPlayer().getVLCVout();
vlcVout.addCallback(this);
vlcVout.setVideoView(mSurfaceView);
vlcVout.attachViews();
final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
final String aout = VLCOptions.getAout(pref);
VLCInstance.getMainMediaPlayer().setAudioOutput(aout);
MediaWrapperListPlayer.getInstance().playIndex(this, 0);
} catch (Exception e) {
Log.e(TAG, e.toString());
}当您获得播放事件时,您需要启用视频轨道。
private void onPlaying() {
stopLoadingAnimation();
VLCInstance.getMainMediaPlayer().setVideoTrackEnabled(true);
}这可能对你有帮助。
https://stackoverflow.com/questions/34633273
复制相似问题