Delete cache when a song is deleted from the database

This commit is contained in:
vfsfitvnm
2022-06-12 15:16:14 +02:00
parent aa27e14e97
commit be8b91b3b0
2 changed files with 12 additions and 0 deletions

View File

@@ -54,6 +54,8 @@ val StopRadioCommand = SessionCommand("StopRadioCommand", Bundle.EMPTY)
val GetCacheSizeCommand = SessionCommand("GetCacheSizeCommand", Bundle.EMPTY)
val DeleteSongCacheCommand = SessionCommand("DeleteSongCacheCommand", Bundle.EMPTY)
@ExperimentalAnimationApi
@ExperimentalFoundationApi
class PlayerService : MediaSessionService(), MediaSession.MediaItemFiller,
@@ -180,6 +182,7 @@ class PlayerService : MediaSessionService(), MediaSession.MediaItemFiller,
.add(StartArtistRadioCommand)
.add(StopRadioCommand)
.add(GetCacheSizeCommand)
.add(DeleteSongCacheCommand)
.build()
val playerCommands = Player.Commands.Builder().addAllCommands().build()
return MediaSession.ConnectionResult.accept(sessionCommands, playerCommands)
@@ -213,6 +216,11 @@ class PlayerService : MediaSessionService(), MediaSession.MediaItemFiller,
GetCacheSizeCommand -> {
return Futures.immediateFuture(SessionResult(SessionResult.RESULT_SUCCESS, bundleOf("cacheSize" to cache.cacheSpace)))
}
DeleteSongCacheCommand -> {
args.getString("videoId")?.let { videoId ->
cache.removeResource(videoId)
}
}
}
return super.onCustomCommand(session, controller, customCommand, args)