[英]How can I fetch the Audio files from Android Device above Android 4.0 like Whatsapp?
I want to show track same as Image and want to play it there. 我想显示与Image相同的曲目,并想在那里播放。
Using below code I can try to fetch Mp3 files but can't play that file there. 使用下面的代码,我可以尝试获取Mp3文件,但不能在那里播放该文件。
So please help me.. 所以请帮帮我..
public void openGalleryAudio(){
Intent intent = new Intent();
intent.setType("audio/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Audio "), SELECT_AUDIO);
}
Using this method I can Find the detail of all Mp3 files from whole sdcard. 使用这种方法,我可以从整个sdcard中查找所有Mp3文件的详细信息。 In this Track_Bean is a Get and Set Method of Different String variables.
在此Track_Bean中是不同String变量的Get and Set方法。
For Example 例如
public class Track_Bean {
private String mTitle = "";
public String getmTitle() {
return mTitle;
}
public void setmTitle(String mTitle) {
this.mTitle = mTitle;
}
}
================================******========================== ================================ ****** ============ ==============
/**
* SD CARD QUERIES
*/
public ArrayList<Track_Bean> getAllSdCardTrack_Beans(Context context) {
ArrayList<Track_Bean> Track_Beans = new ArrayList<Track_Bean>();
Cursor c = context
.getContentResolver()
.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[] { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.ALBUM_ID }, "1=1",
null, null);
if (c.moveToFirst()) {
do {
Track_Bean mTcBean = new Track_Bean();
String mTitle = c
.getString(c
.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));
if(mTitle.trim().endsWith(".mp3") || mTitle.trim().endsWith(".MP3")){
mTcBean.setmTitle(mTitle);
String mArtist = c
.getString(c
.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
mTcBean.setmArtist(mArtist);
//Media Id
String mId = c.getString(c
.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));
mTcBean.setmId(mId);
//ALbumName
String mAlbumName = c
.getString(c
.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));
mTcBean.setmAlbumName(mAlbumName);
String mAlbumID = c
.getString(c
.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID));
mTcBean.setmAlbumId(mAlbumID);
//Path
String mPath = c
.getString(c
.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
mTcBean.setmPath(mPath);
System.out.println("PATH"+mPath);
//Duration
long mDuration = c
.getLong(c
.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));
String mFormattedDuration = DateUtils
.formatElapsedTime(mDuration / 1000);
mTcBean.setmDuration(mFormattedDuration);
Track_Beans.add(mTcBean);
}else{
System.out.println("The Track ext is not Mp3::"+mTitle);
}
} while (c.moveToNext());
if (c != null)
c.close();
}
System.out.println("Size of array::"+Track_Beans.size());
mLv_tracks.setAdapter(new Audio_Post_Adapter(Audio_Fetch.this, Track_Beans));
return Track_Beans;
}
intent
intent
private void getAudio() {
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i,0011);
}
onActivityResult
you get uri
of media onActivityResult
您会获得uri
的媒体 @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0011 && resultCode == Activity.RESULT_OK){
if ((data != null) && (data.getData() != null)){
Uri audioFileUri = data.getData();
Log.e(TAG, "onActivityResult: 232"+audioFileUri);
}
}
}
Output 产量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.