Play mp3 songs from SDcard
<p>I am accessing songs from sdcard in android, songs are displayed in ListView, but i can't play those files.</p>

<p>here is the code:</p>

<pre><code>package com.ex.imageGallery;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.media.MediaPlayer;
import android.net.Uri;

public class temp extends Activity{
      protected static final String TAG = null;
    private Cursor audioCursor;
      private int video_column_index;
      private static String currentposition;
      ListView videolist;
      int count;

      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.list_audio);
            //init_phone_video_grid();
            System.gc();
            final String[] proj = { MediaStore.Audio.Media._ID,
  MediaStore.Audio.Media.DATA,
  MediaStore.Audio.Media.DISPLAY_NAME,
  MediaStore.Audio.Media.SIZE };

        audioCursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,proj, null, null, null);
        count = audioCursor.getCount();
        videolist = (ListView) findViewById(R.id.PhoneVideoList);
        videolist.setAdapter(new AudioAdapter(getApplicationContext()));
        videolist.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                    int position, long id) {
                //System.out.println(proj[0]);
                System.out.println(audioCursor.getString(position));
                //Uri mur = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI+Uri.parse(audioCursor.getString(position));
                try{
                MediaPlayer mp = new MediaPlayer();
                mp.setDataSource(audioCursor.getString(position));
                mp.prepare();
                mp.start();
                }
                catch(Exception ex)
                {
                    System.out.println(ex);
                }


            }



        });
  }

  class AudioAdapter extends BaseAdapter {
      private Context vContext;

      public AudioAdapter(Context c) {
            vContext = c;
      }

      public int getCount() {
            return count;
      }

      public Object getItem(int position) {
            return position;
      }

      public long getItemId(int position) {
            return position;
      }

      public View getView(int position, View convertView, ViewGroup parent) {
            System.gc();
            TextView tv = new TextView(vContext.getApplicationContext());
            String id = null;
            if (convertView == null) {
                  video_column_index = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME);
                  audioCursor.moveToPosition(position);
                  id = audioCursor.getString(video_column_index);
                  video_column_index = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE);
                  audioCursor.moveToPosition(position);
                  id += "Size(KB):" + audioCursor.getString(video_column_index);
                  tv.setText(id);
            } else
                  tv = (TextView) convertView;
            return tv;
      }
}
</code></pre>

<p>}</p>
