0
나는 Exo Player를 사용하여 Android 용 오디오 플레이어를 제작하고 있습니다. 지금까지이 코드를 사용하고 있으며 내 휴대폰에서 다음 정보를 가져 오는 중입니다. 데이터, 이름, 아티스트.정확한 노래 경로 가져 오기 및 URI 작성
public void getMp3Songs() {
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + "!=0";
Cursor cursor = getContentResolver().query(uri, null, selection, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
String name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
String url = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
int songId = cursor.getColumnIndex(MediaStore.Audio.Media._ID);
arrayList.add(new Songs(songId, name, url));
} while (cursor.moveToNext());
}
cursor.close();
}
}
다음으로 필요한 것은 이러한 트랙의 정확한 경로입니다. 그 목적을 위해이 코드를 사용하고 있습니다.
private void initializePlayer(){
player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector()
, new DefaultLoadControl());
simpleExoPlayerView.setPlayer(player);
player.setPlayWhenReady(playWhenReady);
player.seekTo(currentWindow,playbackPosition);
Uri uri = Uri.parse(url);
MediaSource mediaSource = buildMediaSource(uri);
player.prepare(mediaSource, true, false);
}
private MediaSource buildMediaSource(Uri uri) {
return new ExtractorMediaSource(uri,
new DefaultHttpDataSourceFactory("ua"),
new DefaultExtractorsFactory(), null, null);
}
문제는 플레이어를 시작할 때 아무런 문제가 발생하지 않는다는 것입니다. 그 단지 빈 플레이어와 그 아무것도 연주하지. 나는 내가 파일 경로를 여기에서 골치 아파하고 있다고 생각한다. 도와주세요.
"내가 필요한 다음 트랙은이 트랙의 정확한 경로입니다."- 특히 모든 것을 얻을 수 없기 때문에 그러지 않아야합니다. 'ContentUris.withAppendedId()'를 사용하여 해당 내용에 대해'UID'를 생성하고'Uri'를 ExoPlayer와 함께 사용하려면'_ID'를 사용하십시오. – CommonsWare
나는 기울어진다. 나는 단지 어떻게해야할지 모른다. 나는 사방을 수색했다. 몇 가지 샘플 코드를 제공 할 수 있습니까? –
'ContentUris.withAppendedId (MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, songId) ' – CommonsWare