[英]How to play flv stream using MediaPlayer
In my app, I have a buffer recieving flv stream data. 在我的应用程序中,我有一个缓冲区来接收flv流数据。 As flv is not supported on Android, then how to play it?
由于Android不支持flv,那么该如何播放? If I transform the flv stream buffer to mp4, another problem comes, that is:
如果将flv流缓冲区转换为mp4,则会出现另一个问题,即:
How to define the data source of MediaPlayer, as it is a file path or a url usually. 如何定义MediaPlayer的数据源,因为它通常是文件路径或url。 Can anybody help or give me some advices.
谁能帮忙或给我一些建议。
I personally use VideoView.setVideo(uri)
to set a video in the VideoView
. 我个人使用
VideoView.setVideo(uri)
来设置视频在VideoView
。 You can simply convert a video on the server side or your own pc with this ffmpeg command line: 您可以使用以下ffmpeg命令行在服务器端或您自己的PC上简单地转换视频:
ffmpeg -i infile.flv outfile.mp4
Like you should know the function VideoView.setVideo()
expects as the first parameter a Uri
which can be a local path or a http/https url. 就像您应该知道函数
VideoView.setVideo()
期望将Uri
作为第一个参数,它可以是本地路径或http / https url。
If you need to send cookies for the download/streaming with your webserver you can use the hidden function setVideo(Uri, Map<String, String>)
with reflection: 如果您需要发送cookie以便通过Web服务器进行下载/流式传输,则可以使用隐藏函数
setVideo(Uri, Map<String, String>)
进行反射:
HashMap<String, String> header = new HashMap<String, String>();
header.put("Cookie", "--value--");
Method setVideo = videoView.getClass().getMethod("setVideoURI", Uri.class, Map.class);
setVideo.invoke(videoView, Uri.parse(url), header);
But note that you need to catch the possible exceptions which could be throws, for simplification I removed them in the code above. 但是请注意,你需要捕捉可能的例外可能是两罚全中,为简化起见我删除了他们在上面的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.