Closed kdeng00 closed 5 years ago
An idea that may provide an efficient and reliable solution is to retrieve all the track details and store it in a data structure. Once that has completed then insert the the track details into the SQLite database as a transaction.
Continuing with the previous solution instead of iterating through the whole storage device for songs, limit it to a smaller amount initially. It could be some arbitrary amount but should not be too small or too large. In other words, it should not be something like 1 or 200+, 40 seems like a good number.
Configure 40 tracks and insert them into the database. That will reduce the time of adding music. The remainder will be in the added in the background that is where the the solution kicks in. While searching the storage drive for music and configuring tracks, once that completes then insert them into the database via a transaction in case something were to go wrong
Improve upon this further by splitting the search and delegating it to different Kotlin coroutines.
Instead of creating the music library upon the first run of the app make it more flexible. Each time the app is opened there will be a scan of the External Storage (Internal storage will be used for #49 in terms of music) to search for music. For the moment Mp3 songs.
Once the paths of the Mp3 songs have been initialized as a data structure, compare that to what is found in the database of music. If there are Mp3 songs that are not in the database then add those.
If there are songs found in the database but not in the Mp3 data structure then remove those records from the database,
After commit 95ad867 the music adding process spawns multiple coroutines to add music in blocks. An issue with that is that when during that process there is a chance of disruption that could cause undesired results. With the addition from the previous comment the solution applied would not be necessary. Instead add music as the Track model is assigned so in case if the user goes into a different part of the app, the music adding process will essentially pick up where it was left off.
Currently when adding music or updating music, if there are a lot of music files on the phone's storage device or devices then the process takes a while to add music to the library.
Steps to reproduce in debug mode