I am fairly new to exoplayer and I having some difficulties playing audio files (specifically mp3) via external files directory in android.
val trackSelector = DefaultTrackSelector(this)
trackSelector.setParameters(
trackSelector.buildUponParameters().setMaxVideoSizeSd()
)
val player : SimpleExoPlayer = SimpleExoPlayer.Builder(this).setTrackSelector(trackSelector).build()
videoView.player = player
// Create a data source factory.
val dataSourceFactory: DataSource.Factory = DefaultDataSourceFactory(this)
// Create a progressive media source pointing to a stream uri.
val mediaSource: MediaSource = ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(MediaItem.fromUri(Uri.fromFile(getExternalFilesDir("app_tracks/helloaudio.mp3"))))
player.setMediaSource(mediaSource)
player.playWhenReady = true
player.seekTo(0, 0)
player.prepare()
And it gave me an error - Source error
E/ExoPlayerImplInternal: Playback error
com.google.android.exoplayer2.ExoPlaybackException: Source error
at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:554)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:214)
at android.os.HandlerThread.run(HandlerThread.java:67)
Caused by: com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.company.app.android/files/app_tracks/helloaudio.mp3: open failed: EISDIR (Is a directory)
at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:97)
at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:193)
at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:84)
at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1013)
at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:415)
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:919)
Caused by: com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.mindfi.app2.android/files/app_tracks/helloaudio.mp3: open failed: EISDIR (Is a directory)
I check the audio file whether is exists using isExist method, and it return true to me.
I appreciate your help.