创建适用于Android的直播应用 [英] Create a Live Streaming APP for Android
问题描述
我最近遇到了麻烦.
我想开发一个嵌入了实时流的Android App,但我只是不知道如何开始. 我尝试使用嵌入了livestreaming标签的Webview,但是它不起作用(很可能是通过Flash提供流的). 我也尝试过使用VideoView组件,但是它也没有用.
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.
我知道这是有可能的,因为那些发布者拥有自己的APP,但是我们提供的格式通常是Flash.不是移动友好格式.
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.
请有人告诉我有关如何开始或是否有解决方法的任何想法吗?
Can someone, please, show me any idea on how to start or if there is some workaround?
提前谢谢!
我想做的是,例如,以这个流为例: http://new.livestream.com/ATP/lexington2014court1 并显示在我的APP中.
What I would like to do is, like, take this stream, for example: http://new.livestream.com/ATP/lexington2014court1 and show it inside my APP.
推荐答案
我认为我做到了!
首先,我确实使用了livestream.com上的流,但是现在,他们没有实际版本的公共API,但是.... 我从这里得到了很多帮助: new.livestream.com API以获得RTSP
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
因此,有此API调用 http://new.livestream.com/api/accounts /[account_id]/events/[event_id]/viewing_info
So, there is this API call http://new.livestream.com/api/accounts/[account_id]/events/[event_id]/viewing_info
这将向我们返回JSON.然后,我将"rtsp_url"值放入我的VideoURI中.
which return us a JSON. Then, I take the "rtsp_url" value and put it into my VideoURI.
所以这是我的代码: 请用上面获取的JSON中的"rtsp_url"的值替换下面代码中的"{VIDEO_RTSP_URL}".
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.
MainActivity.java
MainActivity.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
activity_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>
现在,由于某种原因,当我连接到Wi-Fi时,流媒体无法正常工作,但是当我使用3G时(我正在实际设备上进行测试.不是仿真器),它可以正常工作,但这是另一个主题
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
总体而言,如果您正在使用Livestream.com之类的流媒体服务,则它们可能会通过API为您提供类似RTSP_URL的内容.您可能只需要使用它即可.
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.
这篇关于创建适用于Android的直播应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!