• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

read a audio file into a byte array from sd card in android

joyson fernandes
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone tell me how do i read the mp3/mp4... audio files into a byte array .The audio files are present on my sdcard.I have been able to retrieve the audio files from my sd card however i do not know how to read the audio files into a byte array.Can some one please help me do this.I am a newbie to android ...any help is appreciable.Thanks.

private void init_phone_music_grid()
String[] proj = { MediaStore.Audio.Media._ID,
MediaStore.Video.Media.SIZE };
musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);
count = musiccursor.getCount();
musiclist = (ListView) findViewById(R.id.listview);
musiclist.setAdapter(new MusicAdapter(getApplicationContext()));

mMediaPlayer = new MediaPlayer();

File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"infor.txt");

byte[] dd;
try {
FileInputStream fns = new FileInputStream(file);
ByteArrayOutputStream baos = new ByteArrayOutputStream();

dd = new byte[fns.available()];

Toast.makeText(getApplicationContext(), "inside fileinputstream"+dd,Toast.LENGTH_LONG).show();

} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block

However when i insert this statement
File file = new File(sdcard,"New_Airtell_2011.mp3");
to read a mp3 file it does not give me the byte array of the mp3 file .Whereas i get the byte array for the text file .

Ulf Dittmer
Posts: 42968
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic