Amin.Frg
Amin.Frg

Reputation: 59

how to play video from byte array in media player

i'm using usb device connected to my android device

this device send me a buffer that contain video frame it dose that continuously .

when i receive the buffer i should put specific header into that and write it to sd card as m4v video file .

then i should play it in media player so far it works fine but i should show the video live . as soon as usb device send me the buffer i should process it and play it so i can show the video .

my question is how to play a video file from byte buffer without store it in sd card ?

Upvotes: 4

Views: 4833

Answers (2)

Clock ZHONG
Clock ZHONG

Reputation: 980

I found jacks205 doesn't mention abstract method close() in Closeable. We also need to write the close(), or the compiling will report the following errors: YourMediaDataSource is not abstract and does not override abstract method close() in Closeable

Upvotes: 0

jacks205
jacks205

Reputation: 555

I know this is awhile since the question was asked, but I am in the same situation where I have a video transport stream coming through a USB connection.

It looks like you need to create a data source that extends a MediaDataSource and provides the readAt() and getSize() methods.

My understanding is Android's MediaPlayer, when you supply a URL/URI as a data source (through setDataSource(), handles all the networking to download the data or retrieve it from storage, and has its own MediaDataSource the player users.

My plan is to create a service that gets the transport stream from the USB device, and constantly update a custom MediaDataSource that I supply to the MediaPlayer.

Here is the only thing I could find on the subject, which was a test written for testing using a MediaDataSource with the MediaPlayer. They read a video from a file into a byte array, and then use that array for the readAt() and getSize() methods.

Only other resources I could find are people supplying strings to the MediaPlayer, but nothing that involves doing their own networking. Also, I'm curious how a constant stream of video is different that just a fixed sized video.

Edit: I wrote a blog post about MediaDataSource and how to get started with it. Here is the link.

Upvotes: 3

Related Questions