Taking the reference I expected the ApplicationMusicPlayer
in my app to pause as soon as I go to the background. It doesn't happen in my app (I don't have any background modes configured for my app). Also - the playback status and queue is not visible in the Apple Music app, butits visible and controllable with the Apple Music Widgets.
Is this actually a bug or I'm doing something obviously wrong? Or everything works as expected and I just don't understand/overinterpret something?
Code:
@main
struct SoundMarkerApp: App {
@Environment(\.scenePhase) var scenePhase
var body: some Scene {
DocumentGroup(newDocument: SongDocument()) { file in
Text("V")
.onAppear {
Task {
do {
let player = ApplicationMusicPlayer.shared
let searchRequest = MusicCatalogResourceRequest<Song>(
matching: \.id,
equalTo: MusicItemID("254945856")
)
let searchResponse = try await searchRequest.response()
player.queue = [searchResponse.items.first!]
try await player.prepareToPlay()
try await player.play()
}
}
}
.onChange(of: scenePhase) { newValue in
print(newValue)
}
}
}
}