Improve process of adding music #43

Closed
opened 2019-03-27 21:10:23 -04:00 by kdeng00 · 5 comments
kdeng00 commented 2019-03-27 21:10:23 -04:00 (Migrated from github.com)

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

  1. Ensure that you have a relatively large collection of music on your phone's storage device (at least 500)
  2. Go to the settings menu
  3. Press Update the Library
  4. Attempt to go to the previous activity by pressing the back button (should be unsuccessful)
  5. Place a break point in the configureTrack() function in TrackManager this is part of the com.example.mear.management package
  6. Once it has stopped on the breakpoint, remove it and continue to run the application
  7. Take note of how the app is unresponsive and how there might be prompts to either close the app or wait. There is no error, it's just processing the songs
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 1. Ensure that you have a relatively large collection of music on your phone's storage device (at least 500) 2. Go to the settings menu 3. Press *Update the Library* 4. Attempt to go to the previous activity by pressing the back button (should be unsuccessful) 5. Place a break point in the *configureTrack()* function in *TrackManager* this is part of the com.example.mear.management package 6. Once it has stopped on the breakpoint, remove it and continue to run the application 7. Take note of how the app is unresponsive and how there might be prompts to either close the app or wait. There is no error, it's just processing the songs
kdeng00 commented 2019-04-06 01:29:20 -04:00 (Migrated from github.com)

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.

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.
kdeng00 commented 2019-04-06 16:18:48 -04:00 (Migrated from github.com)

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

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
kdeng00 commented 2019-04-15 20:38:57 -04:00 (Migrated from github.com)

Improve upon this further by splitting the search and delegating it to different Kotlin coroutines.

Improve upon this further by splitting the search and delegating it to different Kotlin coroutines.
kdeng00 commented 2019-04-20 10:43:17 -04:00 (Migrated from github.com)

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,

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,
kdeng00 commented 2019-04-20 10:52:13 -04:00 (Migrated from github.com)

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.

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.
Sign in to join this conversation.