Android 带ListView的音乐播放器
2010-09-06 08:19:00 来源:WEB开发网android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
< Button
android:id="@+id/cmd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Prepare"
/>
< TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="NAME"
/>
< /LinearLayout>
< ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
< /LinearLayout>
2. 列出所有音乐文件 并转入 adapter
Java代码
Cursor c = getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
null, null, null, null);
String[] from = {MediaStore.Audio.AudioColumns.TITLE,
MediaStore.Audio.AudioColumns.ARTIST};
int[] to = {android.R.id.text1,android.R.id.text2};
final CursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2,c,
from, to);
Cursor c = getContentResolver().query(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
null, null, null, null);
String[] from = {MediaStore.Audio.AudioColumns.TITLE,
MediaStore.Audio.AudioColumns.ARTIST};
int[] to = {android.R.id.text1,android.R.id.text2};
final CursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2,c,
from, to);
3. 使用之
Java代码
list.setAdapter(adapter);
list.setAdapter(adapter);
4. 与音乐播放有关的功能
Java代码
//1. 定义
MediaPlayer mp;
更多精彩
赞助商链接