3

I'm trying to modify (extend) the FileInputStream class so that I can open an encrypted file and use the stream for MediaPlayer's setDataSource(FileDescriptor). Problem is I don't know which method should be overridden to do the decryption inside the stream. I tried overriding all the read() methods, but the mediaPlayer doesn't seem to use them.

Any suggestions?

josephus
  • 8,284
  • 1
  • 37
  • 57
  • what kind of encryption are you using? – st0le Feb 24 '12 at 09:06
  • i'm using RC4. supposedly while read()ing from the FileInputStream, i can decrypt it on the fly. i already implemented the same on-the-fly architecture for a file server so i can just feed the url on the media player, but i want to do it without the use of a server. – josephus Feb 24 '12 at 09:13
  • Probably a stupid question, but Have you tried `new FileInputStream(new CipherInputStream(),)` ofcourse configure the CipherInputStream for RC4 – st0le Feb 24 '12 at 09:24
  • Encryption type does not matter if program can't do ANY modification on data. First think about primary problem - how to modify data being read. – Pointer Null Feb 24 '12 at 09:41
  • 1
    @st0le i tried using cipherinputstream too. one problem is that some android versions/phones do not have a native implementation for RC4, so i had to implement it myself. also, FileInputStream doesn't have a constructor that allows you to instantiate it using another inputstream. i also cannot set CipherInputStream as dataSource because it doesn't have the getFD() method. – josephus Feb 24 '12 at 09:54
  • @mice exactly my point, thanks. i'm hoping to modify the data as it is being read from the FileInputStream. – josephus Feb 24 '12 at 10:00

1 Answers1

5

I don't think that MediaPlayer accepts any kind of InputStream. You can't modify data read from file that are used in MediaPlayer.

MediaPlayer accepts FileDescriptor (processed in native code as reads from real file, no call back to Java). And MediaPlayer acceps http URL.

If you really need modify passed data, consider using local http server and setDataSource with URI.

Community
  • 1
  • 1
Pointer Null
  • 39,597
  • 13
  • 90
  • 111
  • You're right, after hours of trying and failing I finally gave up on having a custom inputstream for MediaPlayer. The fallback plan was, as you and most other sources suggested, create a local http server that can encrypt the data as it is being sent to the player. That wasn't as easy as I thought, as you have to handle resumable download to support an android MediaPlayer connecting to it (hint: Ranges). In the end it was the only way (aside from chunking the video into bite-sizes, weakens the security of the system) – josephus Feb 27 '12 at 10:00
  • @JosephusVillarey So you used this solution and it's working fine? Can you share part of your code? Are you modifying your data bytes and writing it on the local HTTP server? And after you create an URI to this HTTP server and the MediaPlayer reads from it? Thanks. – Derzu Feb 02 '13 at 22:20
  • Yes, exactly. I can't share my code with you, but I can point you to the http server code I based on to make mine work: http://elonen.iki.fi/code/nanohttpd/ – josephus Feb 03 '13 at 11:59
  • @JosephusVillarey Ok, I used just the local http server answered by Mice, and it works. Was not necessary use the nanohttpd code. Thanks. – Derzu Feb 03 '13 at 19:43
  • @JosephusVillarey Can I use local http server mentioned by mice in a case where the currently downloading file served by server to mediaplayer – Ashwin N Bhanushali Apr 05 '13 at 07:18
  • @mice Could you help me at this http://stackoverflow.com/questions/16264225/andriod-shoutcast-internet-radio-filenotfoundexception – IceCream Sandwitch Apr 30 '13 at 05:10
  • Came to this same conclusion before I came across this. Luckily I already have a proxy running. – frostymarvelous Jun 20 '14 at 06:06