diff --git a/LiveApple/Info.plist b/LiveApple/Info.plist index d1d8014..f050495 100644 --- a/LiveApple/Info.plist +++ b/LiveApple/Info.plist @@ -2,12 +2,12 @@ + NSAppleMusicUsageDescription + bad apple BGTaskSchedulerPermittedIdentifiers task - CFBundleDocumentTypes - NSSupportsLiveActivities UIBackgroundModes diff --git a/LiveApple/PlayerController.swift b/LiveApple/PlayerController.swift index 68bdc66..bc4a821 100644 --- a/LiveApple/PlayerController.swift +++ b/LiveApple/PlayerController.swift @@ -63,6 +63,18 @@ class PlayerController: ObservableObject { // using the AVPlayer gives you sound // self.player.play() + // play song via system music player so it keeps playing in the background and sessionkitd things we're not playing media + let player = MPMusicPlayerController.systemMusicPlayer + let query = MPMediaQuery.songs() + query.addFilterPredicate(MPMediaPropertyPredicate(value: "badapple", forProperty: MPMediaItemPropertyTitle)) + player.setQueue(with: query) + do { + try await player.prepareToPlay() + player.play() + } catch { + // if the song doesn't exist, ignore it + } + // doing it manually lets you update while in the background let start = Date() timer = .scheduledTimer(withTimeInterval: 1/30, repeats: true, block: { [unowned self] _ in