Josmomo
Josmomo

Reputation: 11

How does the Twitch-application stream to Android?

I'm currently working on a project to develop a e-sport streaming calendar for a company. The app works fine but the problem is that twitch only lets you stream flash, and for Android that doesn't quite work after Google's decision to remove the support. Http-live-streaming isn't very well supported either so the group is currently at a dead end.

My question is therefore: How does the Twitch-application stream to Android?
It works on Android devices that doesn't support flash or HLS, so there should be another way do it.

Upvotes: 1

Views: 2562

Answers (1)

CarlLee
CarlLee

Reputation: 4192

My guess is it probably used HLS or RTSP(RTMP+RTSP is the most common scenarios) inside its flash client already, the Android app is just merely another stream client implementation.

As of HLS, it doen't need any kind of native support to work on Android, it's just plain simple HTTP, you can even write you own implementation if you want. The native MediaPlayer API Android has already provide implementation. It's the same for RTMP + RTSP.

So, as of your problem, there're two ways I can think to solve it:

  1. Get a router that supports packet sniffering(maybe one router with OpenWRT flashed and tcpdump installed), and reverse-engineer the URL and protocol twitch Android client used, then use it in your app.

    pros: no dependency on twitch app itself

    cons: harder to pull off, may break if twitch changed its internal protocol

  2. Reverse-engineer the Intent twitch app used to pass to its video player Activity, and mimic one of your own to allow user to open the player to watch the stream.

    tools you may find useful: https://play.google.com/store/apps/details?id=uk.co.ashtonbrsc.android.intentintercept

    pros: it's more reliable and more consistent

    cons: may not work if the Intent is private, depends on user installing the twtich app

UPDATE:

  1. I just found out Twitch website works on Android native browser, too. Seems like it used <video> tag from HTML5 standard. So the simplest solution could be just use a WebView to wrap around that stream page, but it's not good for user experience.

    Alternatively, you could write a server-side code which accept a stream page URL as parameter and the video tag as an output and use regular expression or XPath or some XML parser library to extract the <video> tag to client. The client app can just set up a WebView with just that <video> tag inside it. This approach prevents your app from stopping to work if Twitch changes its page structure.

    Also, if you wish not to use WebView, you can extract the src attribute of that <video> tag and play it with Android's native MediaPlayer AP if you want.

Upvotes: 1

Related Questions