从媒体存储中不同歌曲的列表视图中,我需要设置uri路径,以便媒体播放器可以开始使用这首歌曲。
ArrayList<Map<String, Object>> list = EnsembleChansons.getInstance().getList(this, artiste);
ListAdapter adapter = new SimpleAdapter(this, list, R.layout.list_row,new String[]{"title","artist","album","duration","cover"}, new int[]{R.id.unameList, R.id.scoreList,R.id.albumText, R.id.cLeftList, R.id.imageSong});
((SimpleAdapter) adapter).setViewBinder(new SimpleAdapter.ViewBinder(){
@Override
public boolean setViewValue(View view, Object data, String textRepresentation) {
if( (view instanceof ImageView) & (data instanceof Bitmap) ) {
ImageView iv = (ImageView) view;
Bitmap bm = (Bitmap) data;
iv.setImageBitmap(bm);
return true;
}
return false;
}
});
listeChanson.setAdapter(adapter);
listeChanson.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
HashMap<String, String> item = (HashMap<String, String>) parent.getItemAtPosition(position);
String title = item.get("title");
String artist = item.get("artist");
String album = item.get("album");
Toast.makeText(getBaseContext(), title, Toast.LENGTH_LONG).show();
openActivity(v, title, artist, album);
}
});
这是搜索类
public arraylist<map<string,object>>getlist(活动a,字符串艺术家){
ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
resolver = A.getContentResolver();
Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Uri imageUri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
Map<String, Object> temp = new HashMap<>();
Bitmap pochette = null;
Cursor musicCursor = resolver.query(musicUri, new String[]{"_id", "album", "artist", "title", "duration"}, "duration > 0", null, "artist");
if(Artiste != null) {
musicCursor = resolver.query(musicUri, new String[]{"_id", "album", "artist", "title", "duration"}, "duration > 0 and artist LIKE '%" + Artiste+"%'", null, "artist");
}
while(musicCursor.moveToNext()){
temp = new HashMap<String, Object>();
temp.put("title", musicCursor.getString(musicCursor.getColumnIndex("title")));
temp.put("album", musicCursor.getString(musicCursor.getColumnIndex("album")));
temp.put("artist", musicCursor.getString(musicCursor.getColumnIndex("artist")));
temp.put("duration", formateMilliSeccond(musicCursor.getLong(musicCursor.getColumnIndex("duration"))));
Cursor pochetteCursor = resolver.query(imageUri, new String[] {"_id", "album"}, "album = ?", new String[]{musicCursor.getString(1)}, null);
if(pochetteCursor != null && pochetteCursor.moveToFirst()){
long id_de_album = pochetteCursor.getInt(0);
Uri contentUri = ContentUris.withAppendedId(imageUri, id_de_album);
System.out.println(contentUri);
try{
pochette = resolver.loadThumbnail(contentUri, new Size( 100, 100), null);
}
catch (IOException e){
e.printStackTrace();
}
temp.put("cover", pochette);
pochetteCursor.close();
}
list.add(temp);
}
musicCursor.close();
return list;
}
我需要使用音乐选择给定的uri,这样我就可以用mediaplayer开始流媒体了
mp = MediaPlayer.create(this, R.raw.nothing); // need something else to put here
mp.setLooping(true);
mp.seekTo(0);
mp.setVolume(1.0f, 1.0f);
totalTime = mp.getDuration();
谢谢,有些术语是法语的
暂无答案!
目前还没有任何答案,快来回答吧!