I have an Android app targeting SDK 28 so I have the permissions to deal with. I check that the READ_EXTERNAL_STORAGE
is set, but when Exoplayer tries to read the file (which I verified did exist) I see
com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/VID_20190610_200249.mp4: open failed: EACCES (Permission denied).
I can play an asset (file baked into the app) just fine as well as playing from the Internet. I just cannot play a local video stored in my ...DCIM/Camera directory for some reason. Can anyone tell me what I am doing wrong please? My code looks like this:
player = ExoPlayerFactory.newSimpleInstance(this, DefaultTrackSelector())
playerView.player = player
player?.addListener(this)
//TODO: Change this when we are given the embedded video
val dataSource = DefaultDataSourceFactory(this, Util.getUserAgent(this, "Exoplayer"))
var path: String = ""
var mediaSource: ExtractorMediaSource
if (passedUrl == PLAY_TUTORIAL) {
path = "asset:///tutorial_video.mp4"
mediaSource = ExtractorMediaSource.Factory(dataSource).createMediaSource(Uri.parse(path))
} else {
path = passedUrl
val file = File(path)
val uriPath = Uri.fromFile(file)
Timber.d("Path is $uriPath and that file exists = ${file.exists()}")
mediaSource = ExtractorMediaSource.Factory(dataSource).createMediaSource(uriPath)
}
//Setting this to 0 will keep the controls from being hidden otherwise it's in milliseconds
playerView.controllerShowTimeoutMs = 1500
player?.prepare(mediaSource)
When I run the code I see this in the logs:
2019-06-13 21:54:35.048 5774-5774/com.android.myapp D/ViewTutorialActivity: Path is file:///storage/emulated/0/DCIM/Camera/VID_20190610_200249.mp4 and that file exists = true
2019-06-13 21:54:35.076 5774-5846/com.android.myapp D/OpenGLRenderer: Setting buffer count to 3, min_undequeued 1, extraBuffers 0
2019-06-13 21:54:38.077 5774-5968/com.android.myapp E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/VID_20190610_200249.mp4: open failed: EACCES (Permission denied)
at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:73)
Any idea?
OK, this is an Android Q thing. There is a work around by enabling legacy support. The same code works perfectly on prior Android versions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.