3

I am trying to read the contents of music files from my android device though i have been able to retrieve the files and play them i need to read the music files and convert them in to a byte array. Can someone please help me : Following is my code:

 public void retrieve_music_files() {
     music_column_index =   musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA); 
     musiccursor.moveToPosition(position); 
     String filename = musiccursor.getString(music_column_index);
     Cursor musiccursor;
     MediaPlayer mMediaPlayer;
     int music_column_index;

     try {
         if (mMediaPlayer.isPlaying()) {
             mMediaPlayer.reset();
         }
         mMediaPlayer.setDataSource(filename);
         mMediaPlayer.prepare();
         mMediaPlayer.start();
     } catch (Exception e) {
     }    
}
1
  • What are you trying to do with the byte array? Just pass it along to the audio system, or do some internal processing first? Commented Sep 7, 2014 at 6:05

2 Answers 2

1

I used below code for my project. Hope this works for you.

String musicFilePath="your music file path";
byte[] fileByteArray;
File file = new File(musicFilePath);
fileByteArray = new byte[(int)file.length()];
Sign up to request clarification or add additional context in comments.

Comments

0

You should be able to convert any file into an array of bytes following the code in this link.

http://www.mkyong.com/java/how-to-convert-file-into-an-array-of-bytes/

1 Comment

This doesn't decode it down to a stream of uncompressed samples, however.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.