1

I have a byte array of an audio file. Now i want to convert this byte array to audio file and then play it on notification bar or any other way.

To convert byte array to audio file and play it i used following code

    // create temp file that will hold byte array
    File tempMp3 = File.createTempFile("kurchina", "mp3", getCacheDir());
    tempMp3.deleteOnExit();
    FileOutputStream fos = new FileOutputStream(tempMp3);
    fos.write(mp3SoundByteArray); // mp3SoundByteArray is my Byte Array
    fos.close();

    mediaPlayer.reset();

    FileInputStream fis = new FileInputStream(tempMp3);
    mediaPlayer.setDataSource(fis.getFD());

    mediaPlayer.prepare();
    mediaPlayer.start();
} catch (IOException ex) {
    String s = ex.toString();
    ex.printStackTrace();
}

Following this : Play Byte array in MediaPlayer - Android

This code doesn't work.

Now am i doing anything wrong in my above mentioned code ? or how i play my byte array converted audio file in notification panel or anyhow in android?

0 Answers0