![](/img/trans.png)
[英]“PKIX path building failed” and “unable to find valid certification path to requested target” when fetching sbt plugins
[英]Fetching exact path of songs and building a URI
我正在使用 Exo Player 為 android 制作音頻播放器。 到目前為止,我正在使用此代碼並從我的手機中獲取以下信息。 數據、姓名、藝術家。
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);
}
問題是當我啟動播放器時,什么也沒有發生。 它只是一個空白播放器,沒有播放任何內容。 我想我在這里弄亂了文件路徑。 請幫忙。
好的,所以我找到了解決方案,如果有人需要他可以使用它。 問題不在於獲取地址或構建Uri
。 這是在這個特定的部分。 new DefaultHttpDataSourceFactory("ua")
這樣:
DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this,
Util.getUserAgent(this, "idk"), new DefaultBandwidthMeter());
現在在返回MediaSource
使用此實例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.