ghenry22 / cordova-plugin-music-controls2

A Cordova plugin displaying music controls in notifications (cordova-plugin-music-controls)
MIT License
59 stars 60 forks source link

Android: FileNotFoundException throw when no cover is send to the media controls #94

Open bexchauveto opened 1 year ago

bexchauveto commented 1 year ago

Hi, I'm using the plugin in an Ionic 6/Capacitor application currently only for android and when using this plugin, I have this exception thrown when I don't set cover inside the MusicControlsOptions.

java.io.FileNotFoundException: : open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:492)
    at java.io.FileInputStream.<init>(FileInputStream.java:160)
    at com.homerours.musiccontrols.MusicControls.getBitmapFromLocal(MusicControls.java:289)
    at com.homerours.musiccontrols.MusicControls.getBitmapCover(MusicControls.java:276)
    at com.homerours.musiccontrols.MusicControls.-$$Nest$mgetBitmapCover(Unknown Source:0)
    at com.homerours.musiccontrols.MusicControls$2.run(MusicControls.java:186)
    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:923)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
    at libcore.io.Linux.open(Native Method)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
    at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
    at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7542)
    at libcore.io.IoBridge.open(IoBridge.java:478)
    ... 8 more
java.io.FileNotFoundException: www/
    at android.content.res.AssetManager.nativeOpenAsset(Native Method)
    at android.content.res.AssetManager.open(AssetManager.java:874)
    at android.content.res.AssetManager.open(AssetManager.java:851)
    at com.homerours.musiccontrols.MusicControls.getBitmapFromLocal(MusicControls.java:296)
    at com.homerours.musiccontrols.MusicControls.getBitmapCover(MusicControls.java:276)
    at com.homerours.musiccontrols.MusicControls.-$$Nest$mgetBitmapCover(Unknown Source:0)
    at com.homerours.musiccontrols.MusicControls$2.run(MusicControls.java:186)
    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:923)

The problem can easily be solved by checking is infos.cover is empty or not here