Android 视频流示例 [英] Android video streaming example

查看:25
本文介绍了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.

推荐答案

我遇到了同样的问题,但最终我找到了方法.

I had the same problem but finally I found the way.

这是演练:

1- 在您的计算机 (SERVER) 上安装 VLC 并转到 Media->Streaming (Ctrl+S)

1- Install VLC on your computer (SERVER) and go to Media->Streaming (Ctrl+S)

2- 选择要流式传输的文件,或者如果要流式传输网络摄像头或...单击捕获设备"选项卡并进行配置,最后单击流式传输"按钮.

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- 在这里您应该进行流媒体服务器配置,只需转到选项"选项卡并粘贴以下命令:

3- Here you should do the streaming server configuration, just go to "Option" tab and paste the following command:

:sout=#transcode{vcodec=mp4v,vb=400,fps=10,width=176,height=144,acodec=mp4a,ab=32,channels=1,samplerate=22050}:rtp{sdp=rtsp://YOURCOMPUTER_SERVER_IP_ADDR:5544/}

注意:将 YOURCOMPUTER_SERVER_IP_ADDR 替换为您的计算机 IP 地址或任何运行 VLC 的服务器...

NOTE: Replace YOURCOMPUTER_SERVER_IP_ADDR with your computer IP address or any server which is running VLC...

注意:您可以看到,视频编解码器是 android 支持的 MP4V.

NOTE: You can see, the video codec is MP4V which is supported by android.

4- 转到 eclipse 并为媒体播放创建一个新项目.创建一个 VideoView 对象并在 OnCreate() 函数中编写如下代码:

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:

mVideoView = (VideoView) findViewById(R.id.surface_view);

mVideoView.setVideoPath("rtsp://YOURCOMPUTER_SERVER_IP_ADDR:5544/");
mVideoView.setMediaController(new MediaController(this));

5- 在设备上运行 apk(不是模拟器,我没有检查它)并等待播放开始.请考虑缓冲过程大约需要 10 秒...

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 视频流示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆