refactor: remove AudioService from ContentView — all playback state via PlayerViewModel

feat/music-streaming
Laurent 1 month ago
parent 4fa431e9bd
commit e5b5c249b4
  1. 28
      Music/ContentView.swift
  2. 1
      Music/MusicApp.swift

@ -5,7 +5,6 @@ struct ContentView: View {
var library: LibraryViewModel
var player: PlayerViewModel
var scanner: ScannerService
var audio: AudioService
var playlist: PlaylistViewModel
var shazam: ShazamService
var db: DatabaseService
@ -204,9 +203,6 @@ struct ContentView: View {
handleDrop(providers)
return true
}
.onChange(of: audio.currentTime) { _, _ in
player.checkHalfway()
}
.onChange(of: library.trackCount) { _, _ in
if showHome { loadHomeData() }
}
@ -289,10 +285,10 @@ struct ContentView: View {
private var playerControls: some View {
PlayerControlsView(
currentTrack: player.currentTrack,
isPlaying: audio.isPlaying,
currentTime: audio.currentTime,
duration: audio.duration,
volume: audio.volume,
isPlaying: player.isPlaying,
currentTime: player.currentTime,
duration: player.duration,
volume: player.volume,
isShuffled: player.isShuffled,
onPlayPause: {
if player.currentTrack == nil {
@ -302,23 +298,23 @@ struct ContentView: View {
player.play(first)
}
} else {
audio.togglePlayPause()
player.togglePlayPause()
}
},
onNext: { player.next() },
onPrevious: { player.previous() },
onSeek: { audio.seek(to: $0) },
onScrubStart: { audio.beginScrubbing() },
onScrub: { audio.scrub(to: $0) },
onScrubEnd: { audio.endScrubbing(at: $0) },
onVolumeChange: { audio.volume = $0 },
onSeek: { player.seek(to: $0) },
onScrubStart: { player.beginScrubbing() },
onScrub: { player.scrub(to: $0) },
onScrubEnd: { player.endScrubbing(at: $0) },
onVolumeChange: { player.setVolume($0) },
onShuffleToggle: { player.toggleShuffle() },
onNowPlayingTap: { scrollToPlayingTrigger = UUID() }
)
}
private func installKeyboardMonitor() {
keyMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { [audio, player, library, playlist] event in
keyMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { [player, library, playlist] event in
guard event.modifierFlags.intersection([.command, .control, .option, .shift]).isEmpty else {
return event
}
@ -335,7 +331,7 @@ struct ContentView: View {
player.play(first)
}
} else {
audio.togglePlayPause()
player.togglePlayPause()
}
return nil
case 123: // left arrow

@ -24,7 +24,6 @@ struct MusicApp: App {
library: library,
player: player,
scanner: scanner,
audio: audioService,
playlist: playlist,
shazam: shazamService,
db: db,

Loading…
Cancel
Save