Play video from ByteArrayOutputStream on android
android, xamarin
Solution
Assuming you want to use android.media.MediaPlayer to do the task.
Then look at MediaPlayer.setDataSource which options you have:
- String path (a File)
- Uri uri (http:// or content:// scheme)
- FileDescriptor fd
1) Java File won't help you.
2) Uri with http:// is the streaming server on localhost that you mention. I tested playing such a file in my app and capturing network traffic using WireShark for Android, and I captured nothing, probably because traffic on localhost can't be captured. So this may be enough safe to stream through local http server.
3) Uri with content:// scheme gets the data from ContentProvider, which may be your own non-exported provider, where you implement openAssetFile, and use ParcelFileDescriptor.createPipe() and a Thread where you read/decrypt data and write them into the pipe up to AssetFileDescriptor that you returned on openAssetFile. This is also safe option as your ContentProvider is not exported.
So you decide which of 2) or 3) is easier for you to implement.
Problem
I am implementing a video player that has to play an encrypted video file. The file has to be decrypted at runtime in a buffer (say ByteArrayOutputStream) and then the stream has to be fed into a video player to play the movie. Most people suggest to host an instance of a streaming server locally and supply the url to the player. But is this approach safe? What if some uses a network profiler app (Like fiddler for windows) and capture all local network calls. The user will able to get hold of decrypted bytes as they flow between the streaming server and the player and save it locally in a file