Categories

Archives

Searching Audio Files in Android

Searching for Audio Files in Android is so much similar in Display Contact Names in Android (I suggest you to look back at the explanation for a more detailed explanation). The audio formats that Android allows are MP3, AAC, AMR.

public class Main extends ListActivity {
  private Cursor audioCursor;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    audioCursor = this.managedQuery(Audio.Media.EXTERNAL_CONTENT_URI,
        null, null, null, null);
    startManagingCursor(audioCursor);

    String[] columnsToMap = new String[] {Audio.Media.TITLE ,
                                          Audio.Media._ID};
    int[] mapTo = new int[] {android.R.id.text1,android.R.id.text2};

    ListAdapter mAdapter = new SimpleCursorAdapter(this,
        android.R.layout.two_line_list_item ,
        audioCursor, columnsToMap, mapTo);
    this.setListAdapter(mAdapter);
  }
}



Quick Explanation
The thing that you need here is Audio.Media.EXTERNAL_CONTENT_URI, as stated on the the contact display article, managedQuery acts like a sql call and the table this time is Audio.Media.EXTERNAL_CONTENT_URI.
Another thing you might have notice is String[] columnsToMap = new String[] {Audio.Media.TITLE , Audio.Media._ID};. These and a lot more are the columns that can be used.

Source Code
Main.java file for Searching Audio in Android

References
android.provider.MediaStore.Audio.Media
Display Contact Names in Android

Related posts:

  1. Display Contact Names in Android
  2. Calling a Contact in Android
  3. HTML 5 Audio Player
  4. Exporting Bitmap to Image Folder in Android
  5. Clicking Items in ListActivity

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>