advplyr / audiobookshelf-app

Mobile application for Audiobookshelf
https://audiobookshelf.org
GNU General Public License v3.0
1.29k stars 174 forks source link

Playing locally downloaded books causes loop requiring restart (OnePlus) #35

Closed cheezgr8r closed 2 years ago

cheezgr8r commented 2 years ago

When attempting to play a book that has been downloaded locally, the display blanks on and off showing only the background or a dark screen. The only way to break the loop is with a restart. Occurs whether or not connected to same network as server.

Phone is a OnePlus Nord10 5G

advplyr commented 2 years ago

Have you tried with multiple downloads? And streaming audiobooks works fine?

zombiehoffa commented 2 years ago

Are you sure it actually completed the download? I was having this kind of thing going on sometimes when I tried to play a book that didn't and couldn't finish downloading because of the download bug here: https://github.com/advplyr/audiobookshelf-app/issues/34

blueboysthlm commented 2 years ago

Same issue as #8 ?

I have the same issue on a OnePlus 9 Pro with Oxygen OS 11.

Streaming audiobooks works fine.

I can download multiple audiobooks. I can start playing downloaded books, but the phone crashes and shuts down.

cheezgr8r commented 2 years ago

This doesn't seem to be a download error, the downloaded file in comparable in size to the original folder. I've tried a few books both originally in mp3 and m4b formats and the behavior repeats. I did get one to work normally that is in m4b format.

Streaming works fine though!

FlamingoDaBird commented 2 years ago

Hi

I face the same issue, my phone locks up, cant do anything with it. But the audio still plays :) It just flashes with showing me an empty desktop (with the watch) and then locks itself.. rinse and repeat. I must force a hard shut down (power+sound up for 10+ seconds) to be able to use the phone again. Pressing the power button just gives me an empty grey window. The touch interface seems completely dead.

Phones tested:

I wonder if it has something to do with the Oneplus folder access/structure? The application clearly states it has access rights to the folder, when adding it.

Many applications utilizes their own application subfolder within the allowed android storage space for applications and their storage space isn't reachable by other applications. Isolation or whatever... :) not sure if that still is the case, every other android version dishes out new kinds of joy or pain...

Application access that it can be given is access to media files, which I noticed isn't enabled by default. So I tried to give it access and use the DCIM folder where the photos are stored:

***EDIT

when using other audiobook players pointing to the very same folder it works fine, my phone doesn't go bananas. So it seems strictly tied to the audiobookshelf app...

advplyr commented 2 years ago

I wonder if it has something to do with the Oneplus folder access/structure? The application clearly states it has access rights to the folder, when adding it.

Many applications utilizes their own application subfolder within the allowed android storage space for applications and their storage space isn't reachable by other applications. Isolation or whatever... :) not sure if that still is the case, every other android version dishes out new kinds of joy or pain...

I think this is a good analysis. It has something to do with the permissions, and there are so many iterations of androids file system and permissions that it is a nightmare to work with at this point. The app can use its own isolated storage that is not accessible to even the user, but I think this would be a poor experience and is not good practice for media files in general. It would simplify the permission issue though.

In other audio/audiobook apps are you able to play the same audio file you downloaded from audiobookshelf?

FlamingoDaBird commented 2 years ago

Yes, in other audiobook apps I've tried there's no issues with any particular folders. I even made some tests with the same folder added to audiobookshelf and smart audiobook player, the latter had no issues playing from that folder.

I agree that it would certainly add poor user experience to limit it to just the one folder. Would it be possible to add both to solve the issue? If I don't change the default folder it will utilize the "isolated in-app storage" and if I add a folder of my choice it will disregard from that folder? Is that even possible? Could be a win-win for all users :)

Thanks.

zombiehoffa commented 2 years ago

I wonder if there is an easier/less prone to failure way to handle downloads? Dsub syncs stuff to a set directory from subsonic supporting servers no problems and is opensource, so maybe there's a hint in there about how to do downloading in a less problematic way? https://github.com/daneren2005/Subsonic

superpawko commented 2 years ago

I have the same issure.

Downloaded book is crashing phone Book downloaded. When i try play it, screen is starting to flicker, sound is playing. I cant do anything. Phone restart itself.

Oneplus 6 Android 11

I see many oneplus users. above.

advplyr commented 2 years ago

Yeah I believe we determined this is an issue with the cover image. Im hoping someone else can test downloading a book from their server with no cover image, and playing that audiobook. If we can confirm it is the image that will help a lot in figuring this out.

superpawko commented 2 years ago

Yeah I believe we determined this is an issue with the cover image. Im hoping someone else can test downloading a book from their server with no cover image, and playing that audiobook. If we can confirm it is the image that will help a lot in figuring this out.

I tested it for you. Audiobook without cover in a file or in embedded in mp3. result : play locally from downloaded file = > no crash, everything looks fine.

PS: Maybe i should suggest it somewhere else but: When you open app , library if refreshed instead of showing last book, it add stress to server and you have to wait for progress refresh. I was using storytel before, what they do is: When opening app show only audiobook player with last played book. You could maybe also add some kind of information that the progress is not refreshed yet, or when it was checked. Maybe progress history, so we could always go back in case of some kind of error.

advplyr commented 2 years ago

Ah okay, I'm going to look into the cover image today. This has been a big problem for oneplus users.

I'm not sure what you mean about the progress refresh adding stress to the server. Are you seeing performance issues when launching the app? If you are I don't think it would be due to the progress sync, that is a small request.

FlamingoDaBird commented 2 years ago

I tried an m4b without any cover, works fine as @superpawko mentioned :) Tried to download another one directly after that with a cover and it crashed as usual.

advplyr commented 2 years ago

Can you confirm that the downloaded audiobook cover image still shows in the app, and the crash only happens when pressing play?

I can see this is a permissions error, but the confusing part is that permission is granted and the permission error only happens when the cover image is used in the notification (the controls you can access on the lock screen).

superpawko commented 2 years ago

I dont know if you did something. But I have set new privileges deleted old audiobook, downloaded again the same book. Now. The only difference is that I dont see cover in Download manager ( Downloads ). Also there is no cover in notifications. And it is not crashing anymore.

advplyr commented 2 years ago

I haven't changed anything yet, still trying to figure out if you are able to see any downloaded covers in the app. To determine if the crash is only happening when the cover image is used in the notification.

advplyr commented 2 years ago

When you say that no cover is shown in the notification, is it showing the app icon in place of the cover?

superpawko commented 2 years ago

When you say that no cover is shown in the notification, is it showing the app icon in place of the cover?

Yes , App logo. Here is how it was before: https://imgur.com/a/yRcw2LG . Now both books have default covers in Downloads. Did you considered creating discord chat? It could be way easier to communicate :)

advplyr commented 2 years ago

v0.9.36-beta is available on the play store now. I added an additional check when you play an audiobook that will check if the local cover has read permissions, if not it will use the app icon as the cover.

Let me know if that works as intended. I haven't considered a discord server yet, maybe too small of community.

FlamingoDaBird commented 2 years ago

I just tried server v1.6.54 and app v0.9.36-beta on my oneplus nord 2. Still get the same crash playing a local m4b audiobook with an embedded cover.

advplyr commented 2 years ago

Before you play the audiobook, is the cover image visible on the bookshelf and on the downloads page?

FlamingoDaBird commented 2 years ago

Yes it is visible. If I manually remove the jpg cover the download created it works fine to play the m4b audiobook. I thought it used the embedded cover?

superpawko commented 2 years ago

I have downloaded new book. With embedded cover and in cover.jpg. And after downloading in Downlaods this book has cover. This cause app to crash while playing audiobook. My yesterday's experiment with different book was weird because it is not showing the cover in downloads even there is cover in folder and mp3. I tried to replicate it. With another book : download book, delete book, download book again , check if here is a cover in downloads play it. But I was unable to delete it, it was still in Downloads. I killed app. I tried to go to Downloads , app crash. Only deleting local files of app and setting everything new helped. Now I cant set permissions to a folder. I downloaded book, i tried to delete it. Same situation. Nothing is happening. I killed app. Now I cant go to downloads.

Other problems with downloaded books: playback is stoping, book is randomly rewinded few minutes back. Sometimes when it stops and i press play it switches to different last book which i was playing via internet (not downlaoded). Finally I lost my progress of a downloaded book.

advplyr commented 2 years ago

This issue requires a recap of what we know:

  1. Based on the logcat export that @TheBinaryLoop sent me, this happens when the media notification is created with a downloaded image.
  2. The issue is exclusive to OnePlus.
  3. We know the app has read permissions for the image because the cover shows in the app. When pressing play, the app again checks that the path to the image is valid and has read access (code: https://github.com/advplyr/audiobookshelf-app/blob/master/android/app/src/main/java/com/audiobookshelf/app/PlayerNotificationService.kt#L676).

Here are the relevant errors from the logcat:

DatabaseUtils: java.lang.SecurityException: Permission Denial: reading com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/tree/primary%3AAudiobooks/document/primary%3AAudiobooks%2FDer%20Biss%20des%20Winters%2Fcover-ab_wp92sf72ltc6qo2p8z.jpg from pid=2675, uid=10199 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
DatabaseUtils:      at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:873)
DatabaseUtils:      at com.android.externalstorage.ExternalStorageProvider.enforceReadPermissionInner(ExternalStorageProvider.java:161)
DatabaseUtils:      at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:714)
DatabaseUtils:      at android.content.ContentProvider$Transport.enforceFilePermission(ContentProvider.java:704)
DatabaseUtils:      at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:578)
DatabaseUtils:      at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:341)
DatabaseUtils:      at android.os.Binder.execTransactInternal(Binder.java:1170)
AndroidRuntime: FATAL EXCEPTION: SysUiBg
AndroidRuntime: Process: com.android.systemui, PID: 2675
AndroidRuntime: java.lang.SecurityException: Permission Denial: reading com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/tree/primary%3AAudiobooks/document/primary%3AAudiobooks%2FDer%20Biss%20des%20Winters%2Fcover-ab_wp92sf72ltc6qo2p8z.jpg from pid=2675, uid=10199 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
AndroidRuntime:     at android.os.Parcel.createExceptionOrNull(Parcel.java:2373)
AndroidRuntime:     at android.os.Parcel.createException(Parcel.java:2357)
AndroidRuntime:     at android.os.Parcel.readException(Parcel.java:2340)
AndroidRuntime:     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
AndroidRuntime:     at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:153)
AndroidRuntime:     at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:804)
AndroidRuntime:     at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2002)
AndroidRuntime:     at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1940)
AndroidRuntime:     at android.graphics.ImageDecoder$ContentResolverSource.createImageDecoder(ImageDecoder.java:274)
AndroidRuntime:     at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1867)
AndroidRuntime:     at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1860)
AndroidRuntime:     at com.android.systemui.media.MediaDataManager.loadBitmapFromUri(MediaDataManager.kt:472)
AndroidRuntime:     at com.android.systemui.media.MediaDataManager.loadBitmapFromUri(MediaDataManager.kt:443)
AndroidRuntime:     at com.android.systemui.media.MediaDataManager.loadMediaDataInBg(MediaDataManager.kt:331)
AndroidRuntime:     at com.android.systemui.media.MediaDataManager.access$loadMediaDataInBg(MediaDataManager.kt:89)
AndroidRuntime:     at com.android.systemui.media.MediaDataManager$loadMediaData$1.run(MediaDataManager.kt:241)
AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:938)
AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:99)
AndroidRuntime:     at android.os.Looper.loop(Looper.java:233)
AndroidRuntime:     at android.os.HandlerThread.run(HandlerThread.java:67)

I added some additional logs when checking the image file permissions before creating the notification. If someone can send me an updated logcat export with the crash that would be great. I also want to make sure there are no app settings on the OnePlus that would resolve this.

TheBinaryLoop commented 2 years ago

I've created and emailed you a new logcat file

advplyr commented 2 years ago

According to the new logs the image does have read permission. GOT FILE cover-ab_wp92sf72ltc6qo2p8z.jpg | image/jpeg | Can Read: true |isExternalStorageDocument: true

But it is still throwing the same read permission errors above. Not sure what else to try here unfortunately. Hopefully an android dev that owns a OnePlus phone can assist on debugging.

TheBinaryLoop commented 2 years ago

How do you display the image when streaming the audiobook?

advplyr commented 2 years ago

This is only the image that you see in the notification. The PlayerNotificationManager will make a call to the MediaDescriptionAdapter for the method getCurrentLargeIcon when it wants to display the image in the notification. This is where the crash is happening. That is here in the code: https://github.com/advplyr/audiobookshelf-app/blob/master/android/app/src/main/java/com/audiobookshelf/app/AbMediaDescriptionAdapter.kt#L37

soilheart commented 2 years ago

Managed to (unwillingly) replicate this bug on a OnePlus Nord 2 5G

advplyr commented 2 years ago

New version available on the play store v0.9.38-beta that is a temporary workaround to this issue. When playing the audiobook it will check if OnePlus and use the logo as the cover image for the android notification instead.

Can someone confirm this works?

TheBinaryLoop commented 2 years ago

It works. Nice 👍🏼

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: advplyr @.> Sent: Friday, January 21, 2022 9:44:22 PM To: advplyr/audiobookshelf-app @.> Cc: Lukas Eßmann @.>; Mention @.> Subject: Re: [advplyr/audiobookshelf-app] Playing locally downloaded books causes loop requiring restart (OnePlus) (Issue #35)

New version available on the play store v0.9.38-betahttps://github.com/advplyr/audiobookshelf-app/releases/tag/v0.9.38-beta that is a temporary workaround to this issue. When playing the audiobook it will check if OnePlus and use the logo as the cover image for the android notification instead.

Can someone confirm this works?

— Reply to this email directly, view it on GitHubhttps://github.com/advplyr/audiobookshelf-app/issues/35#issuecomment-1018846016, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ADGS77HNWQSLCIWRNMSZDV3UXHASNANCNFSM5IAI7JHQ. You are receiving this because you were mentioned.Message ID: @.***>

FlamingoDaBird commented 2 years ago

Indeed, it works fine on my OnePlus! Thanks.

advplyr commented 2 years ago

The downloader was re-built so I wonder what sort of issues OnePlus will have with this

Theta-Dev commented 2 years ago

I am currently running the latest version (0.9.43) on my OnePlus 6 and there is still the same issue. I cant play downloaded audiobooks with cover images. Trying results in a crash of the system UI, leaving the device unresponsive until I hard-reboot it.

advplyr commented 2 years ago

@FlamingoDaBird Covers were added back for locally playing in v2, so I'm curious if your device can now play audiobooks with locally downloaded covers.

carlocgc commented 2 years ago

Can produce this issue on Android Sony Xperia 1 with app version 0.9.43-beta. Local play causing black screen flicker and lock up. Streaming works fine.

FlamingoDaBird commented 2 years ago

@FlamingoDaBird Covers were added back for locally playing in v2, so I'm curious if your device can now play audiobooks with locally downloaded covers.

Server v2.0.8, android v0.9.43 Downloaded a cover for a book within the server app (mine are usually all embedded), then tried to download the audiobook, got an error message see pic below ( download ok but failed to create library item...)

Screenshot_2022-05-01-16-17-40-61_e9782661401ed6f222682e1e02b74bd4

auromak commented 2 years ago

I'm experiencing this issue on my Moto G Power (app version 0.9.43-beta) as well. The cover image being the cause is nice to know, but I don't think this is exclusive to OnePlus / Sony.

edit: the Moto G Power has a feature called Peek Display that displays a full screen image of the currently playing audiobook's cover when I bump my phone as it's sleeping. Perhaps this abnormal usage of that notification cover image is related to why this is affecting my phone as well? Just thought I'd throw it out there if you're still troubleshooting this issue.

advplyr commented 2 years ago

I'm hoping this attempt will fix it in v0.9.44-beta on the play store. Let me know!

carlocgc commented 2 years ago

I'm hoping this attempt will fix it in v0.9.44-beta on the play store. Let me know!

Not fixed for me on Xperia 1, same result as before.

mgoral commented 2 years ago

I'm hoping this attempt will fix it in v0.9.44-beta on the play store. Let me know!

Fixed for me, thank you!

Motorola moto g pro (XT2043-7), Android 11.

Bostrolicious commented 2 years ago

I'm hoping this attempt will fix it in v0.9.44-beta on the play store. Let me know!

Unfortunately not fixed for me on a Oneplus 7T pro, Android 11.

auromak commented 2 years ago

I'm hoping this attempt will fix it in v0.9.44-beta on the play store. Let me know!

This seems to be working; books with covers that I previously downloaded still cause the phone to crash when attempting to play them, but if I download a new book, it plays just fine (though it's cover is blank, which I assume is due to this recent fix). Thank you so much for all the effort you've put into this project, it is already light years ahead of other options out there!

advplyr commented 2 years ago

The commit yesterday b0c9f29 is not yet deployed but that should fix this confirmed by @carlocgc

If you are only using the APK and not getting from the app store the APK is added to the last release https://github.com/advplyr/audiobookshelf-app/releases/tag/v0.9.44-beta under "app-dev-patch3.apk"

Theta-Dev commented 2 years ago

I have just compiled the latest master myself and can confirm that it works now on my Oneplus 6.

Bostrolicious commented 2 years ago

I tried installing app-dev-patch3.apk, and it indeed solves the problem on my Oneplus 7T pro. Fantastic, thank you so much!

orangebrush72 commented 2 years ago

Hi - I am having the same issue. Phone : Nokia G12 Android version : 11 Security update : 5 April 2022 App version : 0.9.44-beta downloading from Google Play store

What works: Streaming works.

What doesn't: When I download an audiobook with a cover in the folder the book will play but flash a black screen. A hard reset is required and sometimes it will prompt to do a factory reset.

Can confirm (via info from this thread) that manually deleting the cover file from the phone allows the book to play with no error.

Thanks for your efforts, much appreciated.

advplyr commented 2 years ago

Release v0.9.45-beta is pending review on the Google Play Store. For those using the APKs you can get the official release fix.

advplyr commented 2 years ago

This fix is now live in the play store!