Create a Live Streaming APP for Android [closed]

天大地大妈咪最大 提交于 2019-12-02 16:48:08
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

So, there is this API call 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.

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

@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

<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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!