有人可以告诉我如何指定以字节为单位读取音频文件的路径。我已经能够在列表视图中列出来自 sd 卡的歌曲。此外,我已将原始文件夹中存在的音频文件读入字节。但是我无法指定从列表视图中读取所选歌曲的路径。
以下是我的代码:
String[] proj = {
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Video.Media.SIZE
};
musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,proj, null, null, null);
count = musiccursor.getCount();
musiclist = (ListView) findViewById(R.id.PhoneMusicList);
musiclist.setAdapter(new MusicAdapter(getApplicationContext()));
musiclist.setOnItemClickListener(musicgridlistener);
mMediaPlayer = new MediaPlayer();
//To read audio file in bytes
InputStream in = getApplicationContext().getResources().openRawResource(R.raw.Audio);
DataInputStream data = new DataInputStream(in);
BufferedReader br = new BufferedReader(new InputStreamReader(data));
//Adapter
public View getView(int position, View convertView, ViewGroup parent)
{
System.gc();
TextView tv = new TextView(mContext.getApplicationContext());
String id = null;
if (convertView == null)
{
music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME);
musiccursor.moveToPosition(position);
id = musiccursor.getString(music_column_index);
music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE);
musiccursor.moveToPosition(position);
id += " Size(KB):" + musiccursor.getString(music_column_index);
tv.setText(id);
}
else
tv = (TextView) convertView;
return tv;
}
在这里,我正在读取已放置在 raw 文件夹中的文件。但是,我需要阅读列表中已选择的音频文件,但我不知道如何引用它。