我有一个针对SDK 28的Android应用,因此我有权处理。我检查READ_EXTERNAL_STORAGE
是否已设置,但是当Exoplayer尝试读取文件(我确认确实存在)时,我会看到
com.google.android.exoplayer2.upstream.FileDataSource $ FileDataSourceException: java.io.FileNotFoundException: /storage/emulated/0/DCIM/Camera/VID_20190610_200249.mp4:打开失败: EACCES(权限被拒绝)。
我可以很好地播放资产(文件放入应用程序中)以及从Internet播放。由于某种原因,我无法播放存储在... DCIM / Camera目录中的本地视频。谁能告诉我我做错了吗?我的代码如下:
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)
运行代码时,我在日志中看到了这一点:
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)
有什么主意吗?
答案 0 :(得分:0)
好的,这是AndroidQ。通过启用旧版支持可以解决此问题。相同的代码可以在Android早期版本上完美运行。