Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
joyson fernandes
Greenhorn
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()
{
System.gc();
String[] proj = { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Video.Media.SIZE };
musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);
//musiccursor=CursorLoader(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,proj,null,null,null);
count = musiccursor.getCount();
musiclist = (ListView) findViewById(R.id.listview);
musiclist.setAdapter(new MusicAdapter(getApplicationContext()));

musiclist.setOnItemClickListener(musicgridlistener);
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()];
fns.read(dd);

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

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


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
Rancher
Pie
Posts: 42967
73
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic