创建适用于 Android 的直播 APP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24939768/
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
Create a Live Streaming APP for Android
提问by priki
I am having quite a trouble lately.
我最近遇到了很多麻烦。
I want to develop an Android App with a livestreaming embeded, but I just don't know how to start. I tried using an Webview with the livestreaming tag embeded, but it didn't work (most likely the stream is provided via Flash). I also tried to use a VideoView component but it also didn't work.
我想开发一个嵌入了直播的 Android 应用程序,但我只是不知道如何开始。我尝试使用嵌入了直播标签的 Webview,但它不起作用(很可能流是通过 Flash 提供的)。我也尝试使用 VideoView 组件,但它也不起作用。
I know it's possible because those publishers have their own APP, but the format we are provided is usually Flash. Not a mobile friendly format.
我知道这是可能的,因为那些出版商有自己的 APP,但我们提供的格式通常是 Flash。不是移动友好的格式。
Can someone, please, show me any idea on how to start or if there is some workaround?
有人可以告诉我如何开始或是否有一些解决方法的任何想法吗?
Thanks in advance!
提前致谢!
EDIT:
编辑:
What I would like to do is, like, take this stream, for example: http://new.livestream.com/ATP/lexington2014court1and show it inside my APP.
我想做的是,比如,拿这个流,例如:http: //new.livestream.com/ATP/lexington2014court1并在我的 APP 中显示它。
采纳答案by priki
I think I did it!
我想我做到了!
First of all, I am indeed using the stream from livestream.com, but right now, they don't have a public API to the actual version, but.... I got a lot of help from here: new.livestream.com API to get RTSP
首先,我确实在使用来自 livestream.com 的流,但是现在,他们没有实际版本的公共 API,但是......我从这里得到了很多帮助: new.livestream。 com API 获取 RTSP
So, there is this API call http://new.livestream.com/api/accounts/[account_id]/events/[event_id]/viewing_info
所以,有这个 API 调用 http://new.livestream.com/api/accounts/[account_id]/events/[event_id]/viewing_info
which return us a JSON. Then, I take the "rtsp_url" value and put it into my VideoURI.
返回给我们一个 JSON。然后,我将“rtsp_url”值放入我的 VideoURI 中。
So here it goes my code: Please, replace "{VIDEO_RTSP_URL}" in the code below with the value of the "rtsp_url" from the JSON you got above.
所以这里是我的代码:请将下面代码中的“{VIDEO_RTSP_URL}”替换为上面JSON中的“rtsp_url”值。
MainActivity.java
主活动.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.video);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
mediaController.setMediaPlayer(videoView);
Uri video = Uri.parse("{VIDEO_RTSP_URL}");
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.start();
}
activity_main.xml
活动_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.fcl.videoplay.MainActivity" >
<VideoView
android:id="@+id/video"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</RelativeLayout>
Now, for some reason, the streaming is not working when I connect to the Wi-Fi, but it works when I am on 3G (I am testing on a real device. Not an emulator), but this is another topic
现在,出于某种原因,当我连接到 Wi-Fi 时流媒体不起作用,但是当我在 3G 上时它起作用(我在真实设备上测试。不是模拟器),但这是另一个话题
Overall, if you're using a streaming service, like Livestream.com, they might provide you something like this RTSP_URL via an API. You will likely just need to use it.
总的来说,如果您使用的是流媒体服务,例如 Livestream.com,他们可能会通过 API 为您提供类似 RTSP_URL 的内容。您可能只需要使用它。