3

In my app videos are stored as series of encrypted SQLite BLOBs.

In order to play video directly from those SQLite I need to write my own custom ContentProvider. I know how to implement basic ContentProvider over SQL queries, but in this case I have no idea how to do this.

How VideoView.setVideoURI() utilize supplied URI? Either it read is as Cursor or ParcelFileDescriptor or somehow as kind of stream?

Any ideas, clues, hints?

Update

Basically question is not only about ContentProvider, but about streaming/playing video directly from SQLite blobs. It doesn't really matter how to play this video - only precondition: creating of intermediate/temporary video file is prohibited (due to security concerns).

Barmaley
  • 16,638
  • 18
  • 73
  • 146
  • This might help you. http://stackoverflow.com/questions/10182457/android-get-stored-video-from-database – Fahim Jan 12 '16 at 07:16
  • Nope it can't. I've investigated sources - it suggests creation of temp file streamed from BLOBs. In my case it's prohibited. Sorry. – Barmaley Jan 12 '16 at 08:05

1 Answers1

2

You can use ServerSocket.
As VideoView uri you can set localhost url of the server socket (127.0.0.1:PORT).

After you read blob from SQL and decrypt it, write it to the Socket and VideoView will read and play it.
It won't be stored anywhere (just in memory).

You will need to take care of buffering and synchronization of threads.

I recommend to use 2 threads for ServerSocket (one for accepting connection, second for communication with client).
I have experienced that some specific devices tries to open stream twice. If your thread will be blocked by communication with client and won't accept another connection, it could fail with broken pipe.

Milos Fec
  • 828
  • 6
  • 11
  • Good idea. I'll explore this option! – Barmaley Jan 14 '16 at 06:04
  • Should I implement my own http server? Or just use TCP/UDP - not sure that VideoView would be able to understand TCP/UDP - what is your experience? – Barmaley Jan 14 '16 at 09:10
  • Ummm... I see that [stock Media Player supports](http://developer.android.com/guide/appendix/media-formats.html) only `http/rtp/sdp`, that means I have to use some sort of tiny http server. From security point of view it's not good (( Anyway, thanx for your answer... – Barmaley Jan 14 '16 at 10:12
  • I think you need to write just HTTP header at the beginning. – Milos Fec Jan 14 '16 at 11:08
  • I've tried using pipes but media player won't handle it. If you can't use filesystem and want to use default media player, local server looks like only solution. Another option is to use another player library packed with your app (ffmpeg) where you can directly write byte array. – Milos Fec Jan 14 '16 at 11:13
  • Btw, for security reasons you can use some random data for the url (i.e. 127.0.0.1:9876\aI4Gm5d). After accepting connection you need to read http request data from the client. If you can read same data in the url, you know you have the right client. – Milos Fec Jan 14 '16 at 11:18
  • Pls, can you give me an example of writing http header to socket for video streaming? – Barmaley Jan 14 '16 at 11:23
  • Here is some example: http://stackoverflow.com/questions/10788125/a-simple-http-server-with-java-socket – Milos Fec Jan 14 '16 at 11:50
  • In your case it should be enough to write first line (with 200 OK) and content-type. Remember to write \r\n after every line and at the end of the header. – Milos Fec Jan 14 '16 at 11:52