I'm developing an android app that will play mp3 files. However the mp3 files are encrypted on the sd card or sqlite. Either ways, after decryption, i'll have a stream of bytes. How do i play them? MediaPlayer does not take inputstream as param开发者_运维百科eter, so i cannot consider that.
I think you need to store the stream to file system; then you could try using setDataSource
method of MediaPlayer
FileInputStream rawmp3file= new FileInputStream(yourByteArrayAsMp3File);
mediaPlayer.setDataSource(rawmp3file.getFD());
If you could switch to PCM audio source, have a look at AudioTrack class.
The AudioTrack class manages and plays a single audio resource for Java applications. It allows to stream PCM audio buffers to the audio hardware for playback. This is achieved by "pushing" the data to the AudioTrack object using one of the write(byte[], int, int) and write(short[], int, int) methods.
This won't be easy. I've done it before on BlackBerry so I bet it's doable on Android too.
If I were you I'd register a new provider for the a custom "encryptedmp3:" protocol. Then I would specify this in a data source for the MediaPlayer:
mediaplayer.setDataSource(this, URI.parse("encryptedmp3://....yourfile"));
I'm not sure how to create a new protocol handler on Android.
I hope this helps a little bit.
Emmanuel
Take a look at the BASS library (free for non-commercial use).
Here is a link for Android: http://www.un4seen.com/forum/?topic=13225.0
There is BASS_StreamCreateFile function:
HSTREAM BASS_StreamCreateFile(
BOOL mem,
void *file,
QWORD offset,
QWORD length,
DWORD flags
);
Parameters:
mem TRUE = stream the file from memory.
file Filename (mem = FALSE) or a memory location (mem = TRUE).
精彩评论