Amazon Gift Cards

Wednesday, January 7, 2009

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;
  public void onCreate(Bundle savedInstanceState) {

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

    String[] columnsToMap = new String[] {Audio.Media.TITLE , Audio.Media._ID};
    int[] mapTo = new int[] {,};

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

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 file for Searching Audio in Android

Display Contact Names in Android

Update History
   Jan 17, 2012 - Visual Update


Blaboy51 said...

Could you help me i want to know how i can search for album art then display it next to the artist name and song name like in the android music app could you show me how to do that? Please

Unknown said...

Thanks for the example!
Can you please show how to start playing the chosen song with MediaPlayer object? In other words, how can i know full path to the song in order to start playing it?

Thanks alot


Andreas Scheucher said...

Here is a description of another way to search for audio files on android