PlaybackHostState.ets 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { PlayStatus } from '../common/PlayStatus'
  2. export function ensurePlaybackHostStorageDefaults(): void {
  3. if (AppStorage.get('isShowPlay') === undefined) {
  4. AppStorage.setOrCreate('isShowPlay', false)
  5. }
  6. if (AppStorage.get('playbackRuntimeReady') === undefined) {
  7. AppStorage.setOrCreate('playbackRuntimeReady', false)
  8. }
  9. if (AppStorage.get('playbackHostOpenRequestToken') === undefined) {
  10. AppStorage.setOrCreate('playbackHostOpenRequestToken', 0)
  11. }
  12. if (AppStorage.get('playbackHostPlaylistRequestToken') === undefined) {
  13. AppStorage.setOrCreate('playbackHostPlaylistRequestToken', 0)
  14. }
  15. if (AppStorage.get('CONTROL_PlayStatus') === undefined) {
  16. AppStorage.setOrCreate('CONTROL_PlayStatus', PlayStatus.INIT)
  17. }
  18. if (AppStorage.get('progressValue') === undefined) {
  19. AppStorage.setOrCreate('progressValue', 0)
  20. }
  21. if (AppStorage.get('cover') === undefined) {
  22. AppStorage.setOrCreate('cover', '')
  23. }
  24. if (AppStorage.get('currentSong') === undefined) {
  25. AppStorage.setOrCreate('currentSong', undefined)
  26. }
  27. }
  28. export function showPlaybackPlayer(show: boolean): void {
  29. AppStorage.setOrCreate('isShowPlay', show)
  30. }
  31. export function setPlaybackRuntimeReady(ready: boolean): void {
  32. AppStorage.setOrCreate('playbackRuntimeReady', ready)
  33. }
  34. export function requestPlaybackPlayerOpen(): void {
  35. const currentToken = AppStorage.get<number>('playbackHostOpenRequestToken') ?? 0
  36. AppStorage.setOrCreate('isShowPlay', true)
  37. AppStorage.setOrCreate('playbackHostOpenRequestToken', currentToken + 1)
  38. }
  39. export function requestPlaybackPlaylistOpen(): void {
  40. const currentToken = AppStorage.get<number>('playbackHostPlaylistRequestToken') ?? 0
  41. AppStorage.setOrCreate('playbackHostPlaylistRequestToken', currentToken + 1)
  42. }