如何在videoview中播放流视频
Posted
技术标签:
【中文标题】如何在videoview中播放流视频【英文标题】:How to play stream video in videoview 【发布时间】:2021-05-11 06:48:16 【问题描述】:我想用 videoview 播放流视频,但是 video view 无法打开它。 我可以使用 VLC 播放视频流,当我在浏览器中输入 url 时,开始下载 mpeg 文件
我的代码如下:
VideoView videoView = findViewById(R.id.videoView);
videoView.setVideoPath("http://172.16.10.39:3002/2");
videoView.setMediaController(new MediaController(this));
videoView.start();
我在运行时得到以下日志:
2021-05-10 13:05:26.982 5595-5595/ir.irib.sahand.multiviewer I/art: Not late-enabling -Xcheck:jni (already on)
2021-05-10 13:05:26.983 5595-5595/ir.irib.sahand.multiviewer W/art: Unexpected CPU variant for X86 using defaults: x86
2021-05-10 13:05:27.318 5595-5595/ir.irib.sahand.multiviewer W/MediaPlayer: Couldn't open http://172.16.10.39:3002/2: java.io.FileNotFoundException: No content provider: http://172.16.10.39:3002/2
2021-05-10 13:05:27.332 5595-5607/ir.irib.sahand.multiviewer D/NetworkSecurityConfig: No Network Security Config specified, using platform default
2021-05-10 13:05:27.410 5595-5610/ir.irib.sahand.multiviewer I/OpenGLRenderer: Initialized EGL, version 1.4
2021-05-10 13:05:27.410 5595-5610/ir.irib.sahand.multiviewer D/OpenGLRenderer: Swap behavior 1
2021-05-10 13:05:27.413 5595-5610/ir.irib.sahand.multiviewer W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2021-05-10 13:05:27.413 5595-5610/ir.irib.sahand.multiviewer D/OpenGLRenderer: Swap behavior 0
2021-05-10 13:05:27.425 5595-5610/ir.irib.sahand.multiviewer D/EGL_emulation: eglCreateContext: 0xa02f2220: maj 3 min 1 rcv 4
2021-05-10 13:05:27.430 5595-5610/ir.irib.sahand.multiviewer D/EGL_emulation: eglMakeCurrent: 0xa02f2220: ver 3 1 (tinfo 0x9ff8ddb0)
2021-05-10 13:05:27.430 5595-5610/ir.irib.sahand.multiviewer E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
2021-05-10 13:05:27.431 5595-5610/ir.irib.sahand.multiviewer E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
2021-05-10 13:05:27.431 5595-5610/ir.irib.sahand.multiviewer E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
2021-05-10 13:05:27.841 5595-5610/ir.irib.sahand.multiviewer D/EGL_emulation: eglMakeCurrent: 0xa02f2220: ver 3 1 (tinfo 0x9ff8ddb0)
2021-05-10 13:06:06.243 5595-5635/ir.irib.sahand.multiviewer E/MediaPlayer: error (1, -2147483648)
2021-05-10 13:06:06.244 5595-5595/ir.irib.sahand.multiviewer E/MediaPlayer: Error (1,-2147483648)
2021-05-10 13:06:06.245 5595-5595/ir.irib.sahand.multiviewer D/VideoView: Error: 1,-2147483648
2021-05-10 13:06:06.439 5595-5610/ir.irib.sahand.multiviewer D/EGL_emulation: eglMakeCurrent: 0xa02f2220: ver 3 1 (tinfo 0x9ff8ddb0)
有人可以帮助我吗? 谢谢
【问题讨论】:
【参考方案1】:试试这个
video=(VideoView)findViewById(R.id.video);
progressBarLandScape=(ProgressBar)findViewById(R.id.pb);
Uri uri = Uri.parse("link of your video");
video.setVideoURI(uri);
video.requestFocus();
video.setOnInfoListener(new MediaPlayer.OnInfoListener()
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra)
if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END)
progressBarLandScape.setVisibility(View.GONE);
return true;
else if(what == MediaPlayer.MEDIA_INFO_BUFFERING_START)
progressBarLandScape.setVisibility(View.VISIBLE);
return true;
return false;
);
video.start();
【讨论】:
以上是关于如何在videoview中播放流视频的主要内容,如果未能解决你的问题,请参考以下文章
在 Android 中播放 RTSP 流视频时如何保持宽高比?
在 VideoView 中播放流,将 url 转换为 rtsp
如何在 android 的 videoview 中播放 .mp4 视频?