因此,在我正在处理的应用中,我正在尝试合并一个列表视图,该视图会显示用户手机上的所有歌曲。我目前已将其设置为显示所有音乐文件(如下面的代码所示),但我需要一种方法来过滤掉随机媒体文件中的实际歌曲(即在facebook等应用中使用的录音或其他音频文件)谷歌+)。我已经搜索并尝试了多种方法,但没有一种方法被证明是成功的。正如你在我的代码中看到的那样,我正在尝试获得一首歌的持续时间并确保它至少约一分钟的时间。任何和所有的帮助将不胜感激!
谢谢, 欧文
P.S。只要问我是否需要查看更多代码,但我认为这应该足够了。
private void init_phone_music_grid() {
System.gc();
String[] proj = { MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.TITLE,
MediaStore.Video.Media.ARTIST };
musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj, null, null, null);
count = musiccursor.getCount();
musiclist = (ListView) findViewById(R.id.lvTrackList);
musiclist.setAdapter(new MusicAdapter(getApplicationContext()));
musiclist.setOnItemClickListener(musicgridlistener);
mMediaPlayer = new MediaPlayer();
}
private OnItemClickListener musicgridlistener = new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,
long id) {
System.gc();
music_column_index = musiccursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
musiccursor.moveToPosition(position);
String filename = musiccursor.getString(music_column_index);
try {
if (mMediaPlayer.isPlaying()) {
mMediaPlayer.reset();
}
mMediaPlayer.setDataSource(filename);
mMediaPlayer.prepare();
mMediaPlayer.start();
if(mMediaPlayer.isPlaying())
chrono.start();
} catch (Exception e) {
}
}
};
public class MusicAdapter extends BaseAdapter {
private Context mContext;
public MusicAdapter(Context c) {
mContext = 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(mContext.getApplicationContext());
String id = null;
if (convertView == null) {
long size = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION);
if(size > 60000) {
music_column_index = musiccursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
musiccursor.moveToPosition(position);
id = musiccursor.getString(music_column_index);
music_column_index = musiccursor
.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION);
musiccursor.moveToPosition(position);
if(!(musiccursor.getString(music_column_index).equalsIgnoreCase("<unknown>")))
id += " - " + musiccursor.getString(music_column_index);
tv.setText(id);
}
} else
tv = (TextView) convertView;
return tv;
}
}
答案 0 :(得分:4)
使用以下查询获取持续时间超过1分钟的所有媒体
musiccursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
proj, MediaStore.Audio.Media.DURATION + ">= 60000", null, null);