From 8bbeb3b368af1a6b321bbba939bca85ab48494e1 Mon Sep 17 00:00:00 2001 From: mkramer99 <92834107+mkramer99@users.noreply.github.com> Date: Sun, 3 Sep 2023 15:49:03 -0400 Subject: [PATCH 1/3] bottom bar play/pause with last selected media item --- .../SpotifyClone/Views/BottomBar.swift | 53 +++++++++++++++---- .../ShowDetailViews/SmallMediaCover.swift | 2 +- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/SpotifyCloneProject/SpotifyClone/Views/BottomBar.swift b/SpotifyCloneProject/SpotifyClone/Views/BottomBar.swift index 0b0b3bf..c047280 100644 --- a/SpotifyCloneProject/SpotifyClone/Views/BottomBar.swift +++ b/SpotifyCloneProject/SpotifyClone/Views/BottomBar.swift @@ -11,16 +11,23 @@ import SwiftUI struct BottomBar: View { @StateObject var mainVM: MainViewModel + @StateObject var audioManager = RemoteAudio() + //private var medias: SpotifyModel.MediaItem] var showMediaPlayer = false + var mediaDetailVM: MediaDetailViewModel var body: some View { VStack(spacing: 0) { Spacer() Group { - if showMediaPlayer { - BottomMediaPlayerBar(songName: "Nothing But The Beat", - artist: "Ed Sheeran", - cover: Image("nothing-but-the-beat-cover")) + if showMediaPlayer && mediaDetailVM.mainItem != nil { + BottomMediaPlayerBar(songName: mediaDetailVM.mainItem!.title, + artist: mediaDetailVM.mainItem!.authorName, + //cover: Image(mediaDetailVM.mainItem!.imageURL)) + cover: SmallMediaCover(imageURL: mediaDetailVM.mainItem!.imageURL), + audioManager: audioManager, + id: mediaDetailVM.mainItem!.id, + previewURl: mediaDetailVM.mainItem!.previewURL) } BottomNavigationBar(mainVM: mainVM) } @@ -32,8 +39,13 @@ struct BottomBar: View { private struct BottomMediaPlayerBar: View { var songName: String - var artist: String - var cover: Image + var artist: [String] + var cover: SmallMediaCover + @StateObject var audioManager: RemoteAudio + let id: String + let previewURl: String + + var isPlaying: Bool { audioManager.showPauseButton && audioManager.lastItemPlayedID == id } var body: some View { ZStack { @@ -44,12 +56,13 @@ private struct BottomMediaPlayerBar: View { HStack { HStack { cover - .resizeToFit() - .frame(width: 60) + //.resizeToFit() + //.scaledToFit() + .frame(width: 50, height: 50) VStack(alignment: .leading) { Text(songName).font(.avenir(.medium, size: Constants.fontSmall)) .frame(maxWidth: .infinity, alignment: .topLeading) - Text(artist).font(.avenir(.medium, size: Constants.fontXSmall)) + Text(artist.joined(separator: ", ")).font(.avenir(.medium, size: Constants.fontXSmall)) .frame(maxWidth: .infinity, alignment: .topLeading) .opacity(Constants.opacityStandard) } @@ -61,10 +74,30 @@ private struct BottomMediaPlayerBar: View { .resizeToFit() .frame(width: 25, height: 25) .opacity(Constants.opacityStandard) - Image("play") + if audioManager.showPauseButton && !audioManager.lastPlayedURL.isEmpty { + Image("stop") + .resizeToFit() + .frame(width: 25, height: 25) + .padding(.trailing, Constants.paddingStandard) + .onTapGesture { + if isPlaying { + audioManager.pause() + } + } + } else { + Image("play") .resizeToFit() .frame(width: 25, height: 25) .padding(.trailing, Constants.paddingStandard) + .onTapGesture { + if isPlaying { + audioManager.pause() + } else { + audioManager.pause() + audioManager.play(previewURl, audioID: id) + } + } + } } } .frame(height: 60) diff --git a/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/ShowsDetailScreen/ShowDetailViews/SmallMediaCover.swift b/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/ShowsDetailScreen/ShowDetailViews/SmallMediaCover.swift index b1684aa..b7d81c3 100644 --- a/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/ShowsDetailScreen/ShowDetailViews/SmallMediaCover.swift +++ b/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/ShowsDetailScreen/ShowDetailViews/SmallMediaCover.swift @@ -16,7 +16,7 @@ struct SmallMediaCover: View { .foregroundColor(.spotifyMediumGray) .overlay(RemoteImage(urlString: imageURL)) .mask(RoundedRectangle(cornerRadius: Constants.radiusStandard).frame(width: 150, height: 150)) - .frame(width: 150, height: 150) + .frame(width: 50, height: 50) .shadow(color: .spotifyDarkGray.opacity(0.3), radius: 15) } .padding(.bottom, 10) From e9c4fdada6f5269c5d4676f3e08945dd0f52fd8b Mon Sep 17 00:00:00 2001 From: mkramer99 <92834107+mkramer99@users.noreply.github.com> Date: Mon, 4 Sep 2023 10:40:43 -0400 Subject: [PATCH 2/3] rest of files added --- SpotifyCloneProject/SpotifyClone/MainView.swift | 2 +- .../SpotifyClone/Service/HomePage/ArtistDetailScreen.swift | 2 +- .../AlbumDetailScreen/AlbumDetailScreen.swift | 2 +- .../EpisodeDetailScreen/EpisodeDetailScreen.swift | 2 +- .../PlaylistDetailScreen/PlaylistDetailScreen.swift | 2 +- .../ShowsDetailScreen/ShowsDetailScreen.swift | 2 +- .../ActiveSearchingScreen/ActiveSearchingScreen.swift | 5 +++-- 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/SpotifyCloneProject/SpotifyClone/MainView.swift b/SpotifyCloneProject/SpotifyClone/MainView.swift index 300d357..c4acf0c 100644 --- a/SpotifyCloneProject/SpotifyClone/MainView.swift +++ b/SpotifyCloneProject/SpotifyClone/MainView.swift @@ -45,7 +45,7 @@ struct MainView: View { .environmentObject(myLibraryVM) .environmentObject(mediaDetailVM) } - BottomBar(mainVM: mainVM, showMediaPlayer: mainVM.showBottomMediaPlayer) + BottomBar(mainVM: mainVM, showMediaPlayer: mainVM.showBottomMediaPlayer, mediaDetailVM: mediaDetailVM) } .onAppear { mainVM.getCurrentUserInfo() } .onChange(of: mainVM.currentPage) { _ in cleanAllPages() } diff --git a/SpotifyCloneProject/SpotifyClone/Service/HomePage/ArtistDetailScreen.swift b/SpotifyCloneProject/SpotifyClone/Service/HomePage/ArtistDetailScreen.swift index 1b2d194..4b7a456 100644 --- a/SpotifyCloneProject/SpotifyClone/Service/HomePage/ArtistDetailScreen.swift +++ b/SpotifyCloneProject/SpotifyClone/Service/HomePage/ArtistDetailScreen.swift @@ -122,7 +122,7 @@ struct ArtistDetailScreen_Previews: PreviewProvider { VStack { Spacer() BottomBar(mainVM: mainVM, - showMediaPlayer: true) + showMediaPlayer: true, mediaDetailVM: MediaDetailViewModel(mainVM: mainVM)) } } } diff --git a/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/AlbumDetailScreen/AlbumDetailScreen.swift b/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/AlbumDetailScreen/AlbumDetailScreen.swift index e527ffc..9248915 100644 --- a/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/AlbumDetailScreen/AlbumDetailScreen.swift +++ b/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/AlbumDetailScreen/AlbumDetailScreen.swift @@ -107,7 +107,7 @@ struct AlbumDetailScreen_Previews: PreviewProvider { mediaDetailVM: MediaDetailViewModel(mainVM: mainVM)) VStack { Spacer() - BottomBar(mainVM: mainVM, showMediaPlayer: true) + BottomBar(mainVM: mainVM, showMediaPlayer: true, mediaDetailVM: MediaDetailViewModel(mainVM: mainVM)) } } } diff --git a/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/EpisodeDetailScreen/EpisodeDetailScreen.swift b/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/EpisodeDetailScreen/EpisodeDetailScreen.swift index b594551..b018640 100644 --- a/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/EpisodeDetailScreen/EpisodeDetailScreen.swift +++ b/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/EpisodeDetailScreen/EpisodeDetailScreen.swift @@ -159,7 +159,7 @@ struct EpisodeDetailScreen_Previews: PreviewProvider { VStack { Spacer() BottomBar(mainVM: mainVM, - showMediaPlayer: true) + showMediaPlayer: true, mediaDetailVM: MediaDetailViewModel(mainVM: mainVM)) } } } diff --git a/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/PlaylistDetailScreen/PlaylistDetailScreen.swift b/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/PlaylistDetailScreen/PlaylistDetailScreen.swift index ae6c573..d492a5f 100644 --- a/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/PlaylistDetailScreen/PlaylistDetailScreen.swift +++ b/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/PlaylistDetailScreen/PlaylistDetailScreen.swift @@ -112,7 +112,7 @@ struct MediaDetailScreen_Previews: PreviewProvider { mediaDetailVM: MediaDetailViewModel(mainVM: mainVM)) VStack { Spacer() - BottomBar(mainVM: mainVM, showMediaPlayer: true) + BottomBar(mainVM: mainVM, showMediaPlayer: true, mediaDetailVM: MediaDetailViewModel(mainVM: mainVM)) } } } diff --git a/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/ShowsDetailScreen/ShowsDetailScreen.swift b/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/ShowsDetailScreen/ShowsDetailScreen.swift index 70b883c..311d080 100644 --- a/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/ShowsDetailScreen/ShowsDetailScreen.swift +++ b/SpotifyCloneProject/SpotifyClone/Views/MediaDetailScreens/ShowsDetailScreen/ShowsDetailScreen.swift @@ -135,7 +135,7 @@ struct ShowsDetailScreen_Previews: PreviewProvider { mediaDetailVM: MediaDetailViewModel(mainVM: mainVM)) VStack { Spacer() - BottomBar(mainVM: mainVM, showMediaPlayer: true) + BottomBar(mainVM: mainVM, showMediaPlayer: true, mediaDetailVM: MediaDetailViewModel(mainVM: mainVM)) } } } diff --git a/SpotifyCloneProject/SpotifyClone/Views/SearchDetailScreens/ActiveSearchingScreen/ActiveSearchingScreen.swift b/SpotifyCloneProject/SpotifyClone/Views/SearchDetailScreens/ActiveSearchingScreen/ActiveSearchingScreen.swift index 177d606..c1e4d72 100644 --- a/SpotifyCloneProject/SpotifyClone/Views/SearchDetailScreens/ActiveSearchingScreen/ActiveSearchingScreen.swift +++ b/SpotifyCloneProject/SpotifyClone/Views/SearchDetailScreens/ActiveSearchingScreen/ActiveSearchingScreen.swift @@ -31,7 +31,7 @@ struct ActiveSearchingScreen: View { .onChange(of: searchInput) { _ in activeSearchVM.search(for: searchInput) } - BottomBar(mainVM: mediaDetailVM.mainVM) + BottomBar(mainVM: mediaDetailVM.mainVM, mediaDetailVM: mediaDetailVM) } } } @@ -41,9 +41,10 @@ struct ActiveSearchingScreen: View { struct ActiveSearchingScreen_Previews: PreviewProvider { static var previews: some View { + ZStack { ActiveSearchingScreen() - BottomBar(mainVM: MainViewModel()) + BottomBar(mainVM: MainViewModel(), mediaDetailVM: MediaDetailViewModel(mainVM: MainViewModel())) } } } From bbfcc2407352ce2edfd9b5f4dc120db7f28579b0 Mon Sep 17 00:00:00 2001 From: mkramer99 <92834107+mkramer99@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:37:40 -0400 Subject: [PATCH 3/3] removed commented out code --- SpotifyCloneProject/SpotifyClone/Views/BottomBar.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/SpotifyCloneProject/SpotifyClone/Views/BottomBar.swift b/SpotifyCloneProject/SpotifyClone/Views/BottomBar.swift index c047280..6ab9d92 100644 --- a/SpotifyCloneProject/SpotifyClone/Views/BottomBar.swift +++ b/SpotifyCloneProject/SpotifyClone/Views/BottomBar.swift @@ -12,7 +12,6 @@ import SwiftUI struct BottomBar: View { @StateObject var mainVM: MainViewModel @StateObject var audioManager = RemoteAudio() - //private var medias: SpotifyModel.MediaItem] var showMediaPlayer = false var mediaDetailVM: MediaDetailViewModel @@ -20,10 +19,10 @@ struct BottomBar: View { VStack(spacing: 0) { Spacer() Group { + // If there is a selected media object, show the player if showMediaPlayer && mediaDetailVM.mainItem != nil { BottomMediaPlayerBar(songName: mediaDetailVM.mainItem!.title, artist: mediaDetailVM.mainItem!.authorName, - //cover: Image(mediaDetailVM.mainItem!.imageURL)) cover: SmallMediaCover(imageURL: mediaDetailVM.mainItem!.imageURL), audioManager: audioManager, id: mediaDetailVM.mainItem!.id, @@ -56,8 +55,6 @@ private struct BottomMediaPlayerBar: View { HStack { HStack { cover - //.resizeToFit() - //.scaledToFit() .frame(width: 50, height: 50) VStack(alignment: .leading) { Text(songName).font(.avenir(.medium, size: Constants.fontSmall))