Android 视频流示例
我想在我的项目中实现视频流。那么,有没有什么教程可以用呢?视频存储在服务器端。因此,要使用 URL 获取视频并在 Android 上播放。我尝试了一些示例,但出现错误:“抱歉,该视频无法播放”。我正在尝试使用 MP4。
I want to implement video streaming in my project. So, is there any tutorial that works? Videos are stored at server side. So, to fetch video using URL and play it on Android. I tried some examples, but I got error, "Sorry, this video can not be played". I am trying to use MP4.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也遇到了同样的问题,但最终我找到了方法。
操作步骤如下:
1- 在您的计算机(服务器)上安装 VLC 并转到媒体 -> 流式传输 (Ctrl+S)
2- 选择要流式传输的文件,或者如果您想流式传输网络摄像头或...,请单击“捕获设备”选项卡并进行配置,最后单击“流”按钮。
3-在这里您应该进行流媒体服务器配置,只需转到“选项”选项卡并粘贴以下命令:
注意:将 YOURCOMPUTER_SERVER_IP_ADDR 替换为您的计算机 IP 地址或任何运行 VLC 的服务器...
注意:您可以看到,视频编解码器是 Android 支持的 MP4V。
4-转到 eclipse 并为媒体播放创建一个新项目。
创建一个 VideoView 对象并在 OnCreate() 函数中编写一些如下代码:
5-在设备上运行 apk(不是模拟器,我没有检查它)并等待播放开始。请考虑缓冲过程大约需要 10 秒...
问题:有人知道如何减少缓冲时间并几乎实时播放视频吗?
I had the same problem but finally I found the way.
Here is the walk through:
1- Install VLC on your computer (SERVER) and go to Media->Streaming (Ctrl+S)
2- Select a file to stream or if you want to stream your webcam or... click on "Capture Device" tab and do the configuration and finally click on "Stream" button.
3- Here you should do the streaming server configuration, just go to "Option" tab and paste the following command:
NOTE: Replace YOURCOMPUTER_SERVER_IP_ADDR with your computer IP address or any server which is running VLC...
NOTE: You can see, the video codec is MP4V which is supported by android.
4- go to eclipse and create a new project for media playbak.
create a VideoView object and in the OnCreate() function write some code like this:
5- run the apk on the device (not simulator, i did not check it) and wait for the playback to be started. please consider the buffering process will take about 10 seconds...
Question: Anybody know how to reduce buffering time and play video almost live ?
我遇到了同样的问题,并找到了使代码正常工作的解决方案。
android-Sdk/samples/android-?/ApiDemos
中给出的代码工作正常。复制粘贴 Android 项目中的每个文件夹,然后在 MediaPlayerDemo_Video.java 中将要流式传输的视频的路径放入路径变量中。代码中将其留空。以下视频流对我有用:
http://www.pocketjourney.com/downloads/pj/video/known.3gp
我知道 RTSP 协议将用于流媒体,但媒体播放器类支持 http 流媒体,如代码中所述。
我在 google 上搜索了视频的格式,发现如果使用 Quicktime Pro 将视频转换为 mp4 或 3gp,则可以很好地进行流式传输。
我在 android 2.1 上测试了最终的 apk。该应用程序在模拟器上运行得不好。在设备上尝试一下。
我希望这有帮助..
I was facing the same problem and found a solution to get the code to work.
The code given in the
android-Sdk/samples/android-?/ApiDemos
works fine. Copy paste each folder in the android project and then in the MediaPlayerDemo_Video.java put the path of the video you want to stream in the path variable. It is left blank in the code.The following video stream worked for me:
http://www.pocketjourney.com/downloads/pj/video/famous.3gp
I know that RTSP protocol is to be used for streaming, but mediaplayer class supports http for streaming as mentioned in the code.
I googled for the format of the video and found that the video if converted to mp4 or 3gp using Quicktime Pro works fine for streaming.
I tested the final apk on android 2.1. The application dosent work on emulators well. Try it on devices.
I hope this helps..
您的问题很可能出在视频文件上,而不是代码上。您的视频很可能不“安全流式传输”。有关详细信息,请参阅在何处放置要流式传输 Android 的视频。
Your problem is most likely with the video file, not the code. Your video is most likely not "safe for streaming". See where to place videos to stream android for more.