Skip to content

Commit

Permalink
Add QueueView and delete other examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dcvz committed Apr 12, 2024
1 parent 0685476 commit 74d7735
Show file tree
Hide file tree
Showing 42 changed files with 79 additions and 2,240 deletions.
4 changes: 4 additions & 0 deletions Example/SwiftAudio/SwiftAudio.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
9B8819752BC866A300E20DCE /* PlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B8819702BC866A300E20DCE /* PlayerView.swift */; };
9B8819782BC866E800E20DCE /* SwiftAudioEx in Frameworks */ = {isa = PBXBuildFile; productRef = 9B8819772BC866E800E20DCE /* SwiftAudioEx */; };
9B88197A2BC9883200E20DCE /* PlayerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B8819792BC9883200E20DCE /* PlayerViewModel.swift */; };
9B88197C2BC98F5000E20DCE /* QueueView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B88197B2BC98F5000E20DCE /* QueueView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -28,6 +29,7 @@
9B88196F2BC866A300E20DCE /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
9B8819702BC866A300E20DCE /* PlayerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlayerView.swift; sourceTree = "<group>"; };
9B8819792BC9883200E20DCE /* PlayerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerViewModel.swift; sourceTree = "<group>"; };
9B88197B2BC98F5000E20DCE /* QueueView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QueueView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -68,6 +70,7 @@
9B8819792BC9883200E20DCE /* PlayerViewModel.swift */,
9B8819702BC866A300E20DCE /* PlayerView.swift */,
9B88195C2BC8657A00E20DCE /* SwiftAudioApp.swift */,
9B88197B2BC98F5000E20DCE /* QueueView.swift */,
9B8819602BC8657B00E20DCE /* Assets.xcassets */,
9B8819622BC8657B00E20DCE /* SwiftAudio.entitlements */,
9B8819632BC8657B00E20DCE /* Preview Content */,
Expand Down Expand Up @@ -167,6 +170,7 @@
9B8819752BC866A300E20DCE /* PlayerView.swift in Sources */,
9B8819712BC866A300E20DCE /* AudioController.swift in Sources */,
9B88197A2BC9883200E20DCE /* PlayerViewModel.swift in Sources */,
9B88197C2BC98F5000E20DCE /* QueueView.swift in Sources */,
9B88195D2BC8657A00E20DCE /* SwiftAudioApp.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
9 changes: 8 additions & 1 deletion Example/SwiftAudio/SwiftAudio/PlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftAudioEx

struct PlayerView: View {
@ObservedObject var viewModel: ViewModel
@State private var showingQueue = false

let controller = AudioController.shared

Expand All @@ -21,7 +22,7 @@ struct PlayerView: View {
VStack(spacing: 0) {
HStack(alignment: .center) {
Spacer()
Button(action: {}, label: {
Button(action: { showingQueue.toggle() }, label: {
Text("Queue")
.fontWeight(.bold)
})
Expand Down Expand Up @@ -123,6 +124,12 @@ struct PlayerView: View {

Spacer()
}
.sheet(isPresented: $showingQueue) {
QueueView()
#if os(macOS)
.frame(width: 300, height: 400)
#endif
}
.padding(.horizontal, 16)
.padding(.top)
}
Expand Down
65 changes: 65 additions & 0 deletions Example/SwiftAudio/SwiftAudio/QueueView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// QueueView.swift
// SwiftAudio
//
// Created by David Chavez on 4/12/24.
//

import SwiftUI
import SwiftAudioEx

struct QueueView: View {
let controller = AudioController.shared
@Environment(\.dismiss) var dismiss

var body: some View {
NavigationStack {
VStack {
List {
if controller.player.currentItem != nil {
Section(header: Text("Playing Now")) {
QueueItemView(
title: controller.player.currentItem?.getTitle() ?? "",
artist: controller.player.currentItem?.getArtist() ?? ""
)
}
}
Section(header: Text("Up Next")) {
ForEach(controller.player.nextItems as! [DefaultAudioItem]) { item in
QueueItemView(
title: item.getTitle() ?? "",
artist: item.getArtist() ?? ""
)
}
}
}
}
.navigationTitle("Queue")
.toolbar {
Button("Close") {
dismiss()
}
}
}
}
}

struct QueueItemView: View {
let title: String
let artist: String

var body: some View {
VStack(alignment: .leading) {
Text(title)
.fontWeight(.semibold)
Text(artist)
.fontWeight(.light)
}
}
}


#Preview {
QueueView()
}

Loading

0 comments on commit 74d7735

Please sign in to comment.