Play sound via system player

This commit is contained in:
Shadowfacts 2022-09-25 12:16:39 -04:00
parent b545a3bc05
commit 40a71ea83c
2 changed files with 10 additions and 2 deletions

View File

@ -2,12 +2,12 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppleMusicUsageDescription</key>
<string>bad apple</string>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>task</string>
</array>
<key>CFBundleDocumentTypes</key>
<array/>
<key>NSSupportsLiveActivities</key>
<true/>
<key>UIBackgroundModes</key>

View File

@ -63,6 +63,14 @@ 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)
try! await player.prepareToPlay()
player.play()
// doing it manually lets you update while in the background
let start = Date()
timer = .scheduledTimer(withTimeInterval: 1/30, repeats: true, block: { [unowned self] _ in