1
exoplayer2.2を使用してオフラインの曲を再生できません。exoplayerでオフラインの曲を再生する
これは私のコードです。
public void initializePlayer(View view) {
playerView = view.findViewById(R.id.player_background_view);
playerView.setPlayer(player);
player.setPlayWhenReady(true);
player.seekTo(currentWindow, playbackPosition);
Uri uri = Uri.parse("file:///storage/sdcard0/Sounds/Music/song.mp3");
MediaSource mediaSource = buildMediaSource(uri);
player.prepare(mediaSource, true, true);
}
private MediaSource buildMediaSource(Uri uri) {
return new ExtractorMediaSource(uri,
new DefaultHttpDataSourceFactory("exoplayer-codelab"),
new DefaultExtractorsFactory(), null, null);
}
次のエラーが発生しています。
ExoPlayerImplInternal: Source error. com.google.android.exoplayer2.upstream.Loader$UnexpectedLoaderException: Unexpected ClassCastException: libcore.net.url.FileURLConnection cannot be cast to java.net.HttpURLConnection
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:317)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.ClassCastException: libcore.net.url.FileURLConnection cannot be cast to java.net.HttpURLConnection
at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.makeConnection(DefaultHttpDataSource.java:393)
at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.makeConnection(DefaultHttpDataSource.java:350)
at com.google.android.exoplayer2.upstream.DefaultHttpDataSource.open(DefaultHttpDataSource.java:192)
at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:640)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:295)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
誰でも助けてください。