How to play video from an array of bytes in a media player

I am using a USB device connected to my Android device.

this device will send me a buffer containing a video frame; it doses it continuously.

When I receive the buffer, I have to put a specific header in it and write it to the SD card as an m4v file.

then I have to play it in the media player while it works fine, but I have to show the video live. as soon as the USB device sends me a buffer, I have to process it and play it so that I can show the video.

My question is: how to play a video file from a byte buffer without saving it to an SD card?

+4
android byte video
source share
2 answers

I know this time, since the question was asked, but I am in the same situation when I have a stream of video transport going through a USB connection.

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

My understanding is Android MediaPlayer, when you supply a URL / URI as a data source (via setDataSource() , processes all networks to load data or retrieve it from storage, and has its own MediaDataSource for player users.

My plan is to create a service that receives the transport stream from a USB device, and constantly update my own MediaDataSource, which I put on MediaPlayer.

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

Only other resources that I could find were people who supply strings to MediaPlayer, but nothing related to their own network. Also, I'm curious how the constant video stream differs from regular fixed-size video.

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

+2
source share

I found that jacks205 does not mention the abstract close () method in Closeable. We also need to write close (), or the compilation will report the following errors: YourMediaDataSource is not abstract and does not cancel the abstract close () method in Closeable

0
source share

All Articles