Showing posts with label Audio. Show all posts
Showing posts with label Audio. Show all posts

Thursday, June 26, 2014

Audiobook Reader for BB10 now got Built for Blackberry status

Recently I upgraded my Audiobook Reader application pro version for BB10.

This version contains many UI related changes and now it is more aligned to Blackberry design guideline and now it is also awarded Built for Blackberry status.

Apart form UI related changes, this version contains two major changes.

Now it Book auto pauses in case it detect phone call activity.

And there was a very critical bug in application which prevents book to be added from SD card. Though issue was related to BB10 OS, I found one work around and now adding books from SD card works as expected.

Full list of features in current version is as below.
  • Allows adding single file or whole folder with book audio data
  • Supports adding custom bookmark
  • Supports browsing mp3 chapter files and play selected mp3 chapter file
  • Supports chapter skip
  • Supports 2 min, 1 min, 30 sec skip option
  • Supports auto pause on call
  • Supports Play/Pause using HW buttons
  • Supports custom cover art download
  • Advance file browser
  • Supports sleep timer
  • Supports shuffle
  • and some more...
Following is demo for current version.


Hope you will like the updates.

Saturday, January 7, 2012

Playing audio file and getting metadata in Android

As I indicated in my previous post that I am currently learing Android to port my audiobook reader app to android.

I managed to create initial book list screen, and now trying to learn how to play audio file and fetch metadata file.

Playing audio file with android is quite easy, Audio and Video are played using MediaPlayer class and quite easy to use.

Following is sample code to play media file in android.

private MediaPlayer mPlayer;

mPlayer = new MediaPlayer();
mPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
        String path = "/sdcard/music/sample music.mp3";
 mPlayer.setDataSource(path);
 mPlayer.prepare();
 mPlayer.start();    
} catch (Exception e) {
 e.printStackTrace();
}

In above code we are setting data source and then preparing mediaplayer then calling start to play media file. It can be paused by pause API and stopped by calling stop.

Now that I am able to play audio file, I tried to fetch its metadata file to show detais of Audio file to user. Fetching metadata was not as easy as playing file as its requied to use ContentResolver API and at first glance it looks quite strange to use it. After spending some time I managed to fetch metadata using following code.

To fetch metadata first we need to decide which attributes we are instrested in. Following are quite frequently used attributes.
       
String[] TRACK_COLUMNS = new String[] {          
 MediaStore.Audio.AudioColumns.ALBUM,
 MediaStore.Audio.AudioColumns.ARTIST,
 MediaStore.Audio.AudioColumns.DURATION,
 MediaStore.Audio.AudioColumns.TRACK,
 MediaStore.Audio.AudioColumns.YEAR, 
 MediaStore.MediaColumns.SIZE,
 MediaStore.MediaColumns.TITLE,
 MediaStore.MediaColumns.DATA,
 MediaStore.MediaColumns.DISPLAY_NAME
 };
Then we need to use ContentResolver to query audio content provider to fetch metadata. I am instrested in query metadata for perticular file. So I am using MediaStore.MediaColumns.DISPLAY_NAME (filename) as selection and then specifying instrested filename in values array.
ContentResolver resolver = getBaseContext().getContentResolver();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
//Uri uri = Media.getContentUriForPath(path);

String selection = MediaStore.MediaColumns.DISPLAY_NAME + "=?";        
String[] values = new String[] { new File(path).getName() };
Finally calling query API using instrested attributes and specifying required condition, Using Cursor we can retrive required metadata.
Cursor cursor = resolver.query(uri, TRACK_COLUMNS, selection, values, null);
while(cursor.moveToNext()) {             
   for( int i = 0 ; i < cursor.getColumnCount(); ++i ) {
      Log.d("TEST", cursor.getString(i));
   }
}
So that's all, Hope it will be helpful.