florent37 / Flutter-AssetsAudioPlayer

Play simultaneously music/audio from assets/network/file directly from Flutter, compatible with android / ios / web / macos, displays notifications
https://pub.dartlang.org/packages/assets_audio_player
Apache License 2.0
757 stars 368 forks source link

Playing songs from storage is throwing exception. #506

Closed ghost closed 3 years ago

ghost commented 3 years ago

Flutter Version: 2.0.2

Lib Version: 3.0.3

Platform Android: Android 10

Songs from network and assets folder is playing well, but the example code in main_media_query.dart is throwing exception.

Reloaded 0 libraries in 5,168ms.
D/ViewRootImpl@63a4b8c[MainActivity]( 3564): ViewPostIme pointer 0
D/ViewRootImpl@63a4b8c[MainActivity]( 3564): ViewPostIme pointer 1
I/ExoPlayerImpl( 3564): Init 747ac60 [ExoPlayerLib/2.13.2] [m10lte, SM-M105F, samsung, 29]
E/ExoPlayerImplInternal( 3564): Playback error
E/ExoPlayerImplInternal( 3564):   com.google.android.exoplayer2.ExoPlaybackException: Source error
E/ExoPlayerImplInternal( 3564):       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:579)
E/ExoPlayerImplInternal( 3564):       at android.os.Handler.dispatchMessage(Handler.java:103)
E/ExoPlayerImplInternal( 3564):       at android.os.Looper.loop(Looper.java:237)
E/ExoPlayerImplInternal( 3564):       at android.os.HandlerThread.run(HandlerThread.java:67)
E/ExoPlayerImplInternal( 3564):   Caused by: com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: java.io.FileNotFoundException: /storage/emulated/0/Recorders/2021_03_26_10_07_45.mp3: open failed: EACCES (Permission denied)
E/ExoPlayerImplInternal( 3564):       at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:97)
E/ExoPlayerImplInternal( 3564):       at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:201)
E/ExoPlayerImplInternal( 3564):       at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:84)
E/ExoPlayerImplInternal( 3564):       at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1015)
E/ExoPlayerImplInternal( 3564):       at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:415)
E/ExoPlayerImplInternal( 3564):       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/ExoPlayerImplInternal( 3564):       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/ExoPlayerImplInternal( 3564):       at java.lang.Thread.run(Thread.java:919)
E/ExoPlayerImplInternal( 3564):   Caused by: com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: java.io.FileNotFoundException: /storage/emulated/0/Recorders/2021_03_26_10_07_45.mp3: open failed: EACCES (Permission denied)
E/ExoPlayerImplInternal( 3564):       at com.google.android.exoplayer2.upstream.FileDataSource.openLocalFile(FileDataSource.java:166)
E/ExoPlayerImplInternal( 3564):       at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:89)
E/ExoPlayerImplInternal( 3564):       ... 7 more
E/ExoPlayerImplInternal( 3564):   Caused by: java.io.FileNotFoundException: /storage/emulated/0/Recorders/2021_03_26_10_07_45.mp3: open failed: EACCES (Permission denied)
E/ExoPlayerImplInternal( 3564):       at libcore.io.IoBridge.open(IoBridge.java:496)
E/ExoPlayerImplInternal( 3564):       at java.io.RandomAccessFile.<init>(RandomAccessFile.java:289)
E/ExoPlayerImplInternal( 3564):       at java.io.RandomAccessFile.<init>(RandomAccessFile.java:152)
E/ExoPlayerImplInternal( 3564):       at com.google.android.exoplayer2.upstream.FileDataSource.openLocalFile(FileDataSource.java:155)
E/ExoPlayerImplInternal( 3564):       ... 8 more
E/ExoPlayerImplInternal( 3564):   Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
E/ExoPlayerImplInternal( 3564):       at libcore.io.Linux.open(Native Method)
E/ExoPlayerImplInternal( 3564):       at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
E/ExoPlayerImplInternal( 3564):       at libcore.io.BlockGuardOs.open(BlockGuardOs.java:252)
E/ExoPlayerImplInternal( 3564):       at libcore.io.ForwardingOs.open(ForwardingOs.java:167)
E/ExoPlayerImplInternal( 3564):       at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7825)
E/ExoPlayerImplInternal( 3564):       at libcore.io.IoBridge.open(IoBridge.java:482)
E/ExoPlayerImplInternal( 3564):       ... 11 more
I/ExoPlayerImpl( 3564): Release 747ac60 [ExoPlayerLib/2.13.2] [m10lte, SM-M105F, samsung, 29] [goog.exo.core]
V/MediaPlayer-JNI( 3564): native_setup
V/MediaPlayerNative( 3564): constructor
V/MediaPlayerNative( 3564): setListener
V/MediaPlayer-JNI( 3564): reset
V/MediaPlayerNative( 3564): reset
V/MediaPlayer( 3564): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer( 3564): cleanDrmObj: mDrmObj=null mDrmSessionId=null
V/MediaPlayer( 3564): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer( 3564): cleanDrmObj: mDrmObj=null mDrmSessionId=null
V/MediaPlayer-JNI( 3564): release
V/MediaPlayerNative( 3564): setListener
V/MediaPlayerNative( 3564): disconnect
V/MediaPlayerNative( 3564): destructor
V/MediaPlayerNative( 3564): disconnect
W/System.err( 3564): com.github.florent37.assets_audio_player.playerimplem.PlayerFinder$NoPlayerFoundException
W/System.err( 3564):    at com.github.florent37.assets_audio_player.playerimplem.PlayerFinder._findWorkingPlayer(PlayerFinder.kt:69)
W/System.err( 3564):    at com.github.florent37.assets_audio_player.playerimplem.PlayerFinder._findWorkingPlayer(PlayerFinder.kt:87)
W/System.err( 3564):    at com.github.florent37.assets_audio_player.playerimplem.PlayerFinder$_findWorkingPlayer$1.invokeSuspend(Unknown Source:12)
W/System.err( 3564):    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
W/System.err( 3564):    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
W/System.err( 3564):    at android.os.Handler.handleCallback(Handler.java:883)
W/System.err( 3564):    at android.os.Handler.dispatchMessage(Handler.java:100)
W/System.err( 3564):    at android.os.Looper.loop(Looper.java:237)
W/System.err( 3564):    at android.app.ActivityThread.main(ActivityThread.java:7948)
W/System.err( 3564):    at java.lang.reflect.Method.invoke(Native Method)
W/System.err( 3564):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
W/System.err( 3564):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
I/flutter ( 3564): current : null
I/flutter ( 3564): onRedayToPlay : null
I/flutter ( 3564): finished : true
I/flutter ( 3564): current : null
I/flutter ( 3564): onRedayToPlay : null
I/flutter ( 3564): PlatformException(OPEN, null, null, null)
D/ViewRootImpl@63a4b8c[MainActivity]( 3564): MSG_WINDOW_FOCUS_CHANGED 0 1
D/InputMethodManager( 3564): prepareNavigationBarInfo() DecorView@c67db92[MainActivity]
D/InputMethodManager( 3564): getNavigationBarColor() -855310
D/ViewRootImpl@63a4b8c[MainActivity]( 3564): MSG_WINDOW_FOCUS_CHANGED 1 1
D/InputMethodManager( 3564): prepareNavigationBarInfo() DecorView@c67db92[MainActivity]
D/InputMethodManager( 3564): getNavigationBarColor() -855310
E/flutter ( 3564): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(OPEN, null, null, null)
E/flutter ( 3564):
ghost commented 3 years ago

Adding android:usesCleartextTraffic="true" to the android manifest solved the issue, and it was explained here @florent37 please update the ReadMe and example application Android 10.

Sibiselva-N commented 3 years ago

I've added android:usesCleartextTraffic="true" in android manifest but iam still getting the permission denied error (android 10)

ghost commented 3 years ago

Capture

Add android:requestLegacyExternalStorage="true" like the above image in your Androidmanifest.xml file