我的代码如下。
//for clicking the item in the list view
protected void onListItemClick(ListView l, View v, int position, long id)
{
Cursor cursor = adapter.getCursor();
cursor.moveToPosition(position);
String _id = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media._ID));
Uri playableUri= Uri.withAppendedPath(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,_id );
MainActivity.RingStart(getBaseContext(), playableUri, position);
}
//there is another class in which has a method with same name and parameter(RingStart)
public static void RingStart(Context contxt, Uri fileuri,int pos)
{
if(mp!=null && mp.isPlaying())
{
mp.stop();
mp.reset();
}
mp =MediaPlayer.create(contxt, fileuri);
if(oldpos !=pos)
mp.start();
oldpos = pos;
}