androidrookie123
Lurker
Currently I am tasked to create a mp3 player in android.
The requirements are
- add those songs that I add in my vitural SD card to a listview so that
the listview shows the song title.
- from the listview I can select the song and play, stop , resume the song.
but curently now I only know how to display those song title that I put in SD card in textview form . how do I modify my codes below so that it can show the song title on a listview and let it play after I click on the song I selected.?
All your help is appreciated. Thanks.
Below are my codes.
import java.util.ArrayList;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class assignmentTwo extends Activity{
TextView view1;
ListView musiclist;
ArrayAdapter aa;
private ArrayList<String> songs = new ArrayList<String>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
view1=(TextView)findViewById(R.id.tv1);
ContentResolver audioResolver = getBaseContext().getContentResolver();
Cursor audioCursor = audioResolver.query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.AudioColumns.TITLE }, null,null, null);
//Gets the number of rows (number of AUDIO files) returned in the query
int audioCount = audioCursor.getCount();
if (audioCursor.moveToFirst()) {
do {
//Check your DDMS whether the Song Title is being logged in Log Cat.
Log.d("Song Title", audioCursor.getString(0));
String temp =view1.getText().toString();
view1.setText(temp +audioCursor.getString(0)+"\n");
} while (audioCursor.moveToNext());
}
//Close the cursor once action completed
audioCursor.close();
}
}
The requirements are
- add those songs that I add in my vitural SD card to a listview so that
the listview shows the song title.
- from the listview I can select the song and play, stop , resume the song.
but curently now I only know how to display those song title that I put in SD card in textview form . how do I modify my codes below so that it can show the song title on a listview and let it play after I click on the song I selected.?
All your help is appreciated. Thanks.
Below are my codes.
import java.util.ArrayList;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class assignmentTwo extends Activity{
TextView view1;
ListView musiclist;
ArrayAdapter aa;
private ArrayList<String> songs = new ArrayList<String>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
view1=(TextView)findViewById(R.id.tv1);
ContentResolver audioResolver = getBaseContext().getContentResolver();
Cursor audioCursor = audioResolver.query( MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.AudioColumns.TITLE }, null,null, null);
//Gets the number of rows (number of AUDIO files) returned in the query
int audioCount = audioCursor.getCount();
if (audioCursor.moveToFirst()) {
do {
//Check your DDMS whether the Song Title is being logged in Log Cat.
Log.d("Song Title", audioCursor.getString(0));
String temp =view1.getText().toString();
view1.setText(temp +audioCursor.getString(0)+"\n");
} while (audioCursor.moveToNext());
}
//Close the cursor once action completed
audioCursor.close();
}
}