Play video in Android from a bytes stream

Pedriyoo picture Pedriyoo · Feb 1, 2011 · Viewed 11.5k times · Source

Is there any way to play a video from a bytes stream in Android? I'm using an specific communications middleware so I can't just pass the http/rtsp link to the MediaPlayer object.

I was wondering if I can wrap my stream with a local http/rtsp link so I can play the stream instead of waiting until the file is downloaded to play it.

My middleware works over TCP so I've also thought that I can wrap my rtsp datagrams with a tcp datagram and interpret them on the client somehow, after removing the TCP headers.

I'm really surprised that I can't just pass a bytes stream to the MediaPlayer. Thanks in advance.

Answer

Pedriyoo picture Pedriyoo · Feb 6, 2011

Custom streaming in Android isn't as easy as I thought. I've managed to do it but only with very specific videos. MPEG4 Videos that are poorly interleaved seem to be streamable. The farest I've gotten is streaming this video:

http://www.pocketjourney.com/downloads/pj/video/famous.3gp

As Cipi answered me, most formats cannot just be packed in a bytes buffer and pass it to MediaPlayer. They need some headers, tails, etc. I'm not sure which format is contained within the aforementioned file, but I guess it's MPEG4.