aspose file tools*
The moose likes Android and the fly likes read a audio file  into a byte array from sd card in android Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "read a audio file  into a byte array from sd card in android" Watch "read a audio file  into a byte array from sd card in android" New topic
Author

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

joyson fernandes
Greenhorn

Joined: Oct 13, 2012
Posts: 1
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
Marshal

Joined: Mar 22, 2005
Posts: 41880
    
  63
Read this: https://www.coderanch.com/how-to/java/ReadDoesntDoWhatYouThinkItDoes


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: read a audio file into a byte array from sd card in android