Android 使用 VideoView 流式传输或渐进式下载视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2058945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using VideoView for streaming or progressive-download video
提问by Sam Dutton
I'm confused about how VideoView can be used to play video: from a local file, as progressive download and streaming.
我对如何使用 VideoView 播放视频感到困惑:从本地文件,作为渐进式下载和流媒体。
This examplework for me (on 1.5 and 2.0 at least) by downloading the file and playing it locally.
通过下载文件并在本地播放,这个示例对我有用(至少在 1.5 和 2.0 上)。
But is it necessary to download the video before playing: is it possible to play video as progressive download, or by streaming, simply by using setVideoPath or setVideoURI, as in VideoViewDemo in the API samples?
但是是否有必要在播放之前下载视频:是否可以像 API 示例中的 VideoViewDemo 那样,通过使用 setVideoPath 或 setVideoURI 以渐进式下载或流式播放视频?
The VideoViewDemo code suggests using setVideoURI for streaming, but I'm not clear what kind of URL I should be using. Does someone have an example URL for a video that can be streamed to the Android emulator using the VideoViewDemo code?
VideoViewDemo 代码建议使用 setVideoURI 进行流式传输,但我不清楚应该使用哪种 URL。有人有可以使用 VideoViewDemo 代码流式传输到 Android 模拟器的视频的示例 URL 吗?
Can progressive download be used with VideoViewDemo? I get a 'sorry, this video cannot be played' message using setVideoPath with URLs that work fine with the blog example linked to above.(Is this a problem in the emulator? I've tried 1.5 and 2.0.)
VideoViewDemo 可以使用渐进式下载吗?我收到一条“抱歉,无法播放此视频”消息,使用 setVideoPath 和 URL 可以很好地与上面链接的博客示例配合使用。(这是模拟器中的问题吗?我试过 1.5 和 2.0。)
I've found a lot of examples and documentation online but, so far, nothing that really answers this question.
我在网上找到了很多例子和文档,但到目前为止,没有什么能真正回答这个问题。
采纳答案by CommonsWare
is it possible to play video as progressive download, or by streaming, simply by using setVideoPath or setVideoURI, as in VideoViewDemo in the API samples?
是否可以像 API 示例中的 VideoViewDemo 一样,通过使用 setVideoPath 或 setVideoURI 以渐进式下载或流式播放视频?
It should. It certainly works with MediaPlayer
, and VideoView
is just a ~200 line wrapper around MediaPlayer
and a SurfaceView
.
这应该。它当然适用于MediaPlayer
, 并且VideoView
只是一个大约 200 行的包装器MediaPlayer
和一个SurfaceView
.
The VideoViewDemo code suggests using setVideoURI for streaming, but I'm not clear what kind of URL I should be using.
VideoViewDemo 代码建议使用 setVideoURI 进行流式传输,但我不清楚应该使用哪种 URL。
http://
and rtsp://
can work, if the video was encoded properly.
http://
并且rtsp://
可以工作,如果视频编码正确。
Does someone have an example URL for a video that can be streamed to the Android emulator using the VideoViewDemo code?
有人有可以使用 VideoViewDemo 代码流式传输到 Android 模拟器的视频的示例 URL 吗?
This videoworks with MediaPlayer
, except on the Nexus One.
该视频适用于MediaPlayer
,但 Nexus One 除外。
EDIT: Actually, that link works with the Nexus One as well.
编辑:实际上,该链接也适用于 Nexus One。
回答by shaman.sir
It works for simple cases, but only when it is not required to make some custom preparations for requests to get a stream.
它适用于简单的情况,但仅当不需要为获取流的请求进行一些自定义准备时。
This tutorial shows an example of manual streaming emulation for an audio but it can be a little refactored to play video:
本教程展示了一个手动模拟音频的示例,但可以稍微重构以播放视频:
http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/
http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/
(be sure to use FileDescriptor
when setting dataSource
, the API was changed slightly from those times).
(请务必FileDescriptor
在设置时使用dataSource
,API 从那时起略有变化)。
回答by Jaymelson Galang
VideoView can only Stream 3gp videos but i recommend this code to stream your video
VideoView 只能流式传输 3gp 视频,但我建议使用此代码来流式传输您的视频
public void onCreate(Bundle savedInstanceState){
setContentView(R.layout.main);
String videourl = "http://something.com/blah.mp4";
Uri uri = Uri.parse(videourl);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setDataAndType(uri, "video/mp4");
startActivity(intent);
}