19

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.

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?

Thanks in advance!

EDIT:

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.

priki
  • 709
  • 1
  • 7
  • 13
  • 2
    There is no general solution for this kind of question. It depends on the stream. Without any details on that, you won't receive any meaningful answer. – FD_ Jul 24 '14 at 17:04
  • 1
    I guess to create a streaming app you'll need to get familiar with RTP, SIP and related stuff. Take a look at this question http://stackoverflow.com/questions/7332532/creating-rtp-packets-from-android-camera-to-send – Droidman Jul 24 '14 at 17:12
  • Sorry... Maybe I wanst't much clear.. what I would like to do would be like, take this stream http://new.livestream.com/ATP/lexington2014court1 and show it inside my APP. – priki Jul 24 '14 at 19:16
  • Video [stream](http://livestream-f.akamaihd.net/i/exchange_3172596_7sV0MOVk_1@172139/master.m3u8?dw=100&__b__=728&hdnea=st=1406230613~exp=1406231513~acl=/i/exchange_3172596_7sV0MOVk_1@172139/*~hmac=dbbf55bdc2512f2fabfdde569ece9b8e2b7f93ca93c9645f55915633bc163d2d) from that site displays reasonably well in current mobile Chrome. My device is pretty slow and weak, but runs SlimKat. This may be important. – Alex Cohn Jul 24 '14 at 19:42
  • @AlexCohn The link to the stream gives me an "Access Denied" page, both in my computer and my device... Livestream's stream doesn't work on my mobile's browsers but when I click it, I download some file and the video works... weird, huh? – priki Jul 24 '14 at 20:30
  • @AlexCohn some file = master.m3u8. Sometimes it works... sometimes not.. – priki Jul 24 '14 at 20:38

1 Answers1

13

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.

Community
  • 1
  • 1
priki
  • 709
  • 1
  • 7
  • 13