Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

android - 在具有Android 10(Q)和targetSdkVersion = 29的ExoPlayer上播放歌曲的正确方法是什么?(What is the correct way to play songs on ExoPlayer with Android 10 (Q) and targetSdkVersion = 29?)

With the recent changes on Android 10 (Q), trying to play a song from the user's device on an app (that targets sdk version 29 and runs Android 10 ) using ExoPlayer, prints the following log on the console and fails (the song is not played):

(随着Android 10(Q)的最新更改,尝试使用ExoPlayer在用户的设备上播放歌曲(目标版本为sdk版本29 ,运行Android 10 ),并在控制台上打印以下日志,但失败(歌曲为未播放):)

E/libprocessgroup: Error encountered killing process cgroup uid 99420 pid 20294: Permission denied
    com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: java.io.FileNotFoundException: /storage/emulated/0/Music/Nirvana/[1989] - Bleach/01 - Blew.mp3: open failed: EACCES (Permission denied)
        at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:73)
        at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:257)
        at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83)
        at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:939)
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:394)
        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: java.io.FileNotFoundException: /storage/emulated/0/Music/Nirvana/[1989] - Bleach/01 - Blew.mp3: open failed: EACCES (Permission denied)
        at libcore.io.IoBridge.open(IoBridge.java:496)
        at java.io.RandomAccessFile.<init>(RandomAccessFile.java:289)
        at java.io.RandomAccessFile.<init>(RandomAccessFile.java:152)
        at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:65)
        at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:257) 
        at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83) 
        at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:939) 
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:394) 
        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: android.system.ErrnoException: open failed: EACCES (Permission denied)
        at libcore.io.Linux.open(Native Method)
        at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
        at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
        at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
        at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7255)
        at libcore.io.IoBridge.open(IoBridge.java:482)
        at java.io.RandomAccessFile.<init>(RandomAccessFile.java:289) 
        at java.io.RandomAccessFile.<init>(RandomAccessFile.java:152) 
        at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:65) 
        at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:257) 
        at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:83) 
        at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:939) 
        at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:394) 
        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) 

One way that I found on the Internet to solve that problem is to add the following attribute on the Manifest's <application> tag:

(我在Internet上找到的解决该问题的方法之一是在清单的<application>标记上添加以下属性:)

android:requestLegacyExternalStorage="true"

The problem with that solution is that it seems to be temporary and might get deprecated soon.

(该解决方案的问题在于它似乎是临时的,可能很快就会弃用。)


What is the correct way to deal with those changes under those specifications?

(在这些规范下应对这些更改的正确方法是什么?)

  ask by Augusto Carmo translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

See https://stackoverflow.com/a/59037794/2373819

(参见https://stackoverflow.com/a/59037794/2373819)

But looking at the Exoplayer Source Code.

(但是看一下Exoplayer源代码。)

https://github.com/google/ExoPlayer/blob/release-v2/library/core/src/main/java/com/google/android/exoplayer2/upstream/FileDataSource.java

(https://github.com/google/ExoPlayer/blob/release-v2/library/core/src/main/java/com/google/android/exoplayer2/upstream/FileDataSource.java)

Says

(说)

file = new RandomAccessFile(dataSpec.uri.getPath(), "r");

And in API 29 and above file paths are not accessible in public files.

(在API 29及更高版本中,公共文件中不能访问文件路径。)

You should raise a bug in ExoPlayer to use Java a fileDescriptor from a contentresolver instead

(您应该在ExoPlayer中引发一个错误,以使用Java从contentresolver使用fileDescriptor)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...