I am currently trying to utilize the Xamarin CrossMediaManager but there seems to be a problem regarding reading source from the apps internal storage. The source i'm trying to access is : /data/user/0/com.pickle.solenya/files/video/180724-084223550.mp4 This is my app package, and the location is an internal one.
I have tried a with a android content provider and accessing the file from files:// and content:// but without success.
The file does exist, and i have tried with other files, the file is found but the MediaPlayer either returns E/MediaPlayer(12941): Error (-38,0) or throws java.io.IOException: setDataSourceFD failed.: status=0x80000000 | SecurityException
More details around the thrown exceptions:
Couldn't open content://com.pickle.jaguar/video/180724-084223550.mp4: java.io.IOException: setDataSourceFD failed.: status=0x80000000
07-24 14:21:47.367 D/MediaPlayer(10784): setDataSource IOException | SecurityException happend :
07-24 14:21:47.367 D/MediaPlayer(10784): java.io.IOException: setDataSourceFD failed.: status=0x80000000
Requesting the following permissions at app start:
android.permission.RECORD_AUDIO
android.permission.CAMERA
android.permission.INTERNET
android.permission.READ_EXTERNAL_STORAGE
android.permission.WRITE_EXTERNAL_STORAGE
android.permission.ACCESS_WIFI_STATE
android.permission.MEDIA_CONTENT_CONTROL
android.permission.WAKE_LOCK
Related
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):
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:
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?
After further trials, I was able to play a song using ExoPlayer using the Media's Uri.
// id col = `MediaStore.Audio.Media._ID`
val id = cursor.getLong(idColIndex)
val uri = ContentUris.withAppendedId(
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
id
)
...
val songSource = ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(uri)
It successfully played the song without any exceptions being thrown.
See https://stackoverflow.com/a/59037794/2373819
But looking at the Exoplayer Source Code.
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.
You should raise a bug in ExoPlayer to use Java a fileDescriptor from a contentresolver instead
Getting this error in Android 9.0 while Downloading file using DownloadManager.
E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: DownloadManager: Neither user 10173 nor current process has android.permission.ACCESS_ALL_DOWNLOADS.
at android.app.ContextImpl.enforce(ContextImpl.java:1824)
at android.app.ContextImpl.enforceCallingOrSelfPermission(ContextImpl.java:1852)
at com.android.providers.downloads.DownloadProvider.query(DownloadProvider.java:918)
at android.content.ContentProvider.query(ContentProvider.java:1074)
at android.content.ContentProvider.query(ContentProvider.java:1166)
at android.content.ContentProvider$Transport.query(ContentProvider.java:246)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:102)
at android.os.Binder.execTransact(Binder.java:731)
i have Added "android:networkSecurityConfig=#xml/network_security_config" in the Manifest file.
In my application, I am playing files from URL using MediaPlayer API.
It plays the remote file very well, the problem comes while handling errors,
1] When a file is not available on a remote URL (i.e. 404)
error message in IOExcpeiton reads, "Prepare failed.: status=0x1"
2] When the phone is not connected to internet exception message is same i.e.
"Prepare failed.: status=0x1"
How do we differentiate between 404 & no connectivity states for better handling of exceptions?
So far I have understood the IOException with the error message "Prepare failed.: status=0x1" appears only when a requested resource file or URL not available
For Error : Prepare failed.: status=0x1
Ref: Android MediaPlayer throwing "Prepare failed.: status=0x1" on 2.1, works on 2.2
I do not know if this is your issue, but I just found a solution to the problem the described by Tuszy above. I could read the file I was creating from external storage but not from Cache.
The solution is that the read write permissions when writing the file are different.
Please see this excellent explanation in this blog I found.
http://blog.weston-fl.com/android-mediaplayer-prepare-throws-status0x1-error1-2147483648/
Ref : Internet Connection Error
getting an UnknownHostException will mean that the application was
able to connect to the Internet
No it doesn't. It means the application was unable to resolve the host name. That could be because the host name doesn't exist, or because it was unable to connect to the Internet to resolve it.
When there is no Internet connection.
No specific exception. "There is no Internet connection" doesn't have a well-defined meaning. The condition resolves to one of the other failure modes below.
When the URL cannot be found.
If the host cannot be found, UnknownHostException. If the content part of the URL cannot be found, HTTP 404.
When the request timed out.
ConnectException with 'connection timed out' as the message, or SocketTimeoutException if it's a read timeout.
When the website is down.
ConnectException with 'connection refused' as the message.
When access is denied.
HTTP 403.
============
Download a audio content(MP3) from website See you again.mp3 and rename to
See you again.mp3
See you again.mp3 Can play/preview mp3 with GooglePlay BUT
See you again.mp3 can NOT be played/previewed with GooglePlay,a Permission Denial was thrown like below:
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/audio/media/40 from pid=1532, uid=1000 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
Could anyone help me to answer my doubts --> Why Android throw the Permission Denial
PS: LG Nexus still exist this issue
when i use MediaPlayer playing .mp3 file,the system will report error log:
Prepare failed.: status=0xFFFFFF8E
but the playing music is normal,there is not exception.
And according to my observations,as if it come out only in relatively high ROM version,such as 4.0,in 2.3 there is no error.
What is the reason, how to solve?