From assets all working fine!
But from external storage no.
This is my exoplayer instance:
// ExoPlayer
val renderesFactory = DefaultRenderersFactory(
this,
DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF
)
val trackSelector = DefaultTrackSelector()
exoPlayer = ExoPlayerFactory.newSimpleInstance(
this@PlayerService,
renderesFactory,
trackSelector
)
exoPlayer!!.addListener(exoPlayerListener)
Here I'm trying to build a path:
val dirPath = applicationContext.getExternalFilesDir(audio.uri)!!.absolutePath
val filePath = "$dirPath/001.mp3"
val audioFile = File(filePath)
val uri = Uri.fromFile(audioFile)
prepareToPlay(uri)
audio.uri --> "Downloads/audio_reading/"
And this is prepareToPlay() method:
private fun prepareToPlay(uri: Uri) {
if (uri != currentUri) {
currentUri = uri
val userAgent = Util.getUserAgent(this@PlayerService, "ExoPlayer")
val mediaSource = ExtractorMediaSource(
uri,
DefaultDataSourceFactory(this@PlayerService, userAgent),
DefaultExtractorsFactory(), null, null
)
exoPlayer!!.prepare(mediaSource)
}
}
When I start app and click "play" I'm getting that error:
E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.music.app/files/Downloads/audio_reading/001.mp3: open failed: EISDIR (Is a directory)
at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:73)
at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:250)
at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83)
at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:886)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.music.app/files/Downloads/audio_reading/001.mp3: open failed: EISDIR (Is a directory)
at libcore.io.IoBridge.open(IoBridge.java:485)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:288)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:151)
at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:65)
at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:250)?
at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83)?
at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:886)?
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:381)?
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)?
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)?
at java.lang.Thread.run(Thread.java:764)?
Caused by: android.system.ErrnoException: open failed: EISDIR (Is a directory)
at libcore.io.IoBridge.open(IoBridge.java:475)
Can anybody help?
question from:
https://stackoverflow.com/questions/65914475/how-to-play-file-from-external-storage-in-exoplayer 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…