How to play audio byte stream in android?

I am developing an Android application that will play mp3 files. However, mp3 files are encrypted on the SD card or in sqlite. In any case, after decryption, I will have a stream of bytes. How can I reproduce them? MediaPlayer does not accept the input stream as a parameter, so I cannot take this into account.

+5
source share
3 answers

I think you need to save the stream to the file system; then you can try using the MediaPlayer methodsetDataSource

FileInputStream rawmp3file= new FileInputStream(yourByteArrayAsMp3File);
mediaPlayer.setDataSource(rawmp3file.getFD());

If you can switch to a PCM sound source, check out the AudioTrack class.

AudioTrack Java . PCM . "" AudioTrack , (byte [], int, int) write (short [], int, int) .

+2

. BlackBerry, , Android.

, encryptedmp3:. MediaPlayer:

mediaplayer.setDataSource(this, URI.parse("encryptedmp3://....yourfile"));

, Android.

, .

0

Take a look at the BASS library (free for non-commercial use).
Here is the link for Android: http://www.un4seen.com/forum/?topic=13225.0

There is a function BASS_StreamCreateFile :

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).
-1
source

All Articles