InnerTune icon indicating copy to clipboard operation
InnerTune copied to clipboard

Downloads wont play

Open owencz1998 opened this issue 2 years ago β€’ 28 comments

Checklist

  • [X] I am able to reproduce the bug with the latest version.
  • [X] I've checked that there is no issue about this bug.
  • [X] This issue contains only one bug.
  • [X] The title of this issue accurately describes the bug.

Steps to reproduce the bug

Download a song After a while the downloads won't play

Expected behavior

Downloads should play and work all the time.

Actual behavior

After a while my downloads will not play and have to redownload them all but happens again.

Screenshots/Screen recordings

https://user-images.githubusercontent.com/96526481/174396431-bcddd90b-4f64-42ca-9a3d-559f3b7e9b11.mp4

Logs

Unable to provide as waiting on a new pc hope someone has the same issue

Music version

0.3 1

Android version

Android 12

Additional information

If no one has this issue I'll send a log as soon as my new computer arrives thanks

owencz1998 avatar Jun 17 '22 20:06 owencz1998

Go to /Android/data/com.zionhuang.music/files/media and if there are files. Then copy them out, add .mp3 suffix, and open them with a music player. This will check if the downloaded media is valid.

z-huang avatar Jun 18 '22 01:06 z-huang

Just checked I'm on samsung and the file explorer doesn't show a lot of android data files I think samsung is giving up on there file explorer lol so I had to download Google file explorer instead but it's saying I have 15 songs in the files but actually iv downloaded 99 songs so some reason something is deleting my songs even tho I keep having download them all again and again.

owencz1998 avatar Jun 18 '22 04:06 owencz1998

Screenshot_20220618-104919_Solid Explorer.jpg

Screenshot_20220618-104934_Music.jpg

As u can see I have 99 songs that say there all downloaded and apparently all I have is what's in the file explorer which is only 14

owencz1998 avatar Jun 18 '22 09:06 owencz1998

How often does this happen? i.e. How long between the time that you downloaded the songa and the songs were deleted?

z-huang avatar Jun 18 '22 10:06 z-huang

Can happen the same day it randomly starts to play up or over time but not sure if it's doing it when I'm not on the app to but yeah iv had to redownload my songs everyday dude but doesn't last long till 1 by 1 they start to do it again mate

owencz1998 avatar Jun 18 '22 11:06 owencz1998

Kinda hard to say how long it does it as newer music I download works but like 90% of my downloaded music isn't working 😞

owencz1998 avatar Jun 18 '22 11:06 owencz1998

Let's see if other people have the same issue.

z-huang avatar Jun 18 '22 14:06 z-huang

No worries mate its definitely confusing and hope someone has the same issue

owencz1998 avatar Jun 18 '22 15:06 owencz1998

I have the same problem with my galaxy a8. after a certain time, downloads will no longer be played. I can then remove it and download it again but after a while the problem comes back and the process starts all over again.

siggi1984 avatar Jun 19 '22 10:06 siggi1984

I'm glad I'm not the only one haha hopefully this can be a easy and quick fix

owencz1998 avatar Jun 19 '22 10:06 owencz1998

Are u able to provide a log file for this issue mate as its driving crazy haha

owencz1998 avatar Jun 19 '22 14:06 owencz1998

I can reproduce this as well. @Alliba described it perfectly.

bacteriostat avatar Jun 29 '22 12:06 bacteriostat

06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal: Playback error
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:   com.google.android.exoplayer2.ExoPlaybackException: Sourceerror
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:5)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:39)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at android.os.Handler.dispatchMessage(Handler.java:102)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at android.os.Looper.loop(Looper.java:223)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at android.os.HandlerThread.run(HandlerThread.java:67)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:   Caused by: com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.zionhuang.music/files/media/69d5e05e155c7117cf377f0a9363916d: open failed: ENOENT (No such file or directory)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:20)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at com.google.android.exoplayer2.upstream.DefaultDataSource.open(DefaultDataSource.java:60)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at com.google.android.exoplayer2.upstream.ResolvingDataSource.open(ResolvingDataSource.java:5)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:3)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:4)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:6)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at java.lang.Thread.run(Thread.java:923)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:   Caused by: java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.zionhuang.music/files/media/69d5e05e155c7117cf377f0a9363916d: open failed: ENOENT (No such fileor directory)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at libcore.io.IoBridge.open(IoBridge.java:492)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at java.io.RandomAccessFile.<init>(RandomAccessFile.java:289)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at java.io.RandomAccessFile.<init>(RandomAccessFile.java:152)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at com.google.android.exoplayer2.upstream.FileDataSource.open(FileDataSource.java:6)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       ... 8 more
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:   Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at libcore.io.Linux.open(Native Method)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7584)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       at libcore.io.IoBridge.open(IoBridge.java:478)
06-29 18:27:45.248  2792  7798 E ExoPlayerImplInternal:       ... 11 more

Managed to get the exception that is occurring when the song is being played. But nothing surprising here just File Not Found exception. Something else is deleting the songs.

The file name (/storage/emulated/0/Android/data/com.zionhuang.music/files/media/69d5e05e155c7117cf377f0a9363916d) looks weird though, maybe that's the reason?

Edit: I am running Android 11 with Stock Android

bacteriostat avatar Jun 29 '22 13:06 bacteriostat

The file name (/storage/emulated/0/Android/data/com.zionhuang.music/files/media/69d5e05e155c7117cf377f0a9363916d) looks weird though, maybe that's the reason?

The file name is the md5 hash of the song id.

z-huang avatar Jun 29 '22 13:06 z-huang

I'll use another phone to test.

z-huang avatar Jun 29 '22 13:06 z-huang

Had any issues on this been found 😁

owencz1998 avatar Jun 29 '22 20:06 owencz1998

Not yet. I tested on an Android 11 Xiaomi phone and an Android 10 Samsung phone, and didn't find downloaded files missing. Hope if any developer who has this issue can help me figure out the cause.

z-huang avatar Jul 02 '22 15:07 z-huang

Is it possible to do with permissions as there isn't any and maybe android 12 is removing the files

owencz1998 avatar Jul 02 '22 16:07 owencz1998

Feels like a android 12 feature that's cleaning my device to free up storage and that's causing them files to be deleted ill be checking to see if I can change something for the app

owencz1998 avatar Jul 02 '22 16:07 owencz1998

@owencz1998 I am on Android 11 and have lots of storage. Android won't delete it, since the songs are saved as User data.

One thing I noticed is that Album art is saved but only songs are getting deleted.

bacteriostat avatar Jul 02 '22 16:07 bacteriostat

https://github.com/z-huang/music/blob/6ca40149a01e047d3bf3673b168c255ca1b58f7f/app/src/main/java/com/zionhuang/music/repos/SongRepository.kt#L116-L118

@z-huang Isn't this supposed to work when the songs are loaded? If this works, we can at least see exactly when the song is deleted.

EDIT:

My bad. Looks like there is no check of whether the song actually exists when the app is loaded. All the entries are just fetched from the local DB. I think it would be wise to make some checks before displaying the songs.

bacteriostat avatar Jul 02 '22 16:07 bacteriostat

So for downloading the songs, the app is using Android's download manager service, which has had some changes in API 29 (Android 10).

The problem is occurring because Android's DownloadIdleService deletes the files that are not visible in the Downloads UI. Here's a stack-overflow issue describing the problem: https://stackoverflow.com/questions/46501822/downloaded-files-get-deleted-automatically

In the code, setVisibleInDownloadsUi is set to false and it is also deprecated on API 29 and above. Which means Android 29 or higher will automatically delete files after some time.

Also found this javadoc for .setDestinationUri function image

bacteriostat avatar Jul 02 '22 18:07 bacteriostat

@bacteriostat nice work hope this is the exact problem 😁nice job

owencz1998 avatar Jul 02 '22 19:07 owencz1998

I was close with saying the system is deleting the music 🀣🀣I'm new to this and learning the coding side but your knowledge is brilliant @bacteriostat

owencz1998 avatar Jul 02 '22 19:07 owencz1998

I was close with saying the system is deleting

Yeah you were right. I am working on a solution. Been years since I touched Android development, so finding a little hard.

bacteriostat avatar Jul 02 '22 19:07 bacteriostat

Nice one man 😁

owencz1998 avatar Jul 02 '22 19:07 owencz1998

@bacteriostat Thanks for your research! So, a quick fix is to rename the file after download completes. But eventually, I'll discard Android download manager and create a download service for #13.

z-huang avatar Jul 03 '22 03:07 z-huang

@z-huang I am not so familiar with the code base so not able to figure out file renaming. You can go ahead with the change if it is easy to implement.

bacteriostat avatar Jul 03 '22 07:07 bacteriostat