From 6244317f3aca455fea5d9c949b8a9b672826bb88 Mon Sep 17 00:00:00 2001 From: BilalKhanWDI Date: Mon, 15 Jul 2024 20:10:33 +0530 Subject: [PATCH] - Updated the play pause and record button usage, also added it to appear over all subviews. - MAde dynamic name for saving in files with the current Timestamp in seconds - Added Icons for playhouse , also stopped other interactions while playing. - Added lazy loading to WebSeries watch_show_listing - Added Lazy loading to Games --- .../KaraokePause.imageset/Contents.json | 26 ++++++ .../Karaoke/KaraokePause.imageset/pause.png | Bin 0 -> 560 bytes .../KaraokePause.imageset/pause@2x.png | Bin 0 -> 1186 bytes .../KaraokePause.imageset/pause@3x.png | Bin 0 -> 1461 bytes WOKA/Audio Books/AudioBookDetailsVC.swift | 2 +- WOKA/Audio Books/AudioBookHomeVC.swift | 17 ++-- WOKA/Audio Books/AudioBookHomeVM.swift | 25 +++--- WOKA/Audio Books/ContinueAudioCell.swift | 2 +- WOKA/Audio Books/ContinueAudioListDM.swift | 2 +- WOKA/Audio Books/ListenAudioListingDM.swift | 75 ++++------------ WOKA/Games/Controller/GamesListVC.swift | 12 +++ WOKA/Games/Games.storyboard | 46 +++++++++- WOKA/Games/ViewModel/GamesListVM.swift | 35 ++++++-- .../Controller/JWKaraokePlayerVC.swift | 81 ++++++++++++------ WOKA/Karaoke/Karaoke.storyboard | 4 +- WOKA/Theme/Controller/PlayerVC.swift | 1 + WOKA/WebSeries/Controller/WebSeriesVC.swift | 9 ++ WOKA/WebSeries/JWPlayerManager.swift | 23 +++-- .../WebSeries/View/WebSeriesEpisodeCell.swift | 4 +- WOKA/WebSeries/ViewModel/WebSeriesVM.swift | 23 ++++- WOKA/WebSeries/WebSeries.storyboard | 46 +++++++++- 21 files changed, 305 insertions(+), 128 deletions(-) create mode 100644 WOKA/Assets/Assets.xcassets/Karaoke/KaraokePause.imageset/Contents.json create mode 100644 WOKA/Assets/Assets.xcassets/Karaoke/KaraokePause.imageset/pause.png create mode 100644 WOKA/Assets/Assets.xcassets/Karaoke/KaraokePause.imageset/pause@2x.png create mode 100644 WOKA/Assets/Assets.xcassets/Karaoke/KaraokePause.imageset/pause@3x.png diff --git a/WOKA/Assets/Assets.xcassets/Karaoke/KaraokePause.imageset/Contents.json b/WOKA/Assets/Assets.xcassets/Karaoke/KaraokePause.imageset/Contents.json new file mode 100644 index 0000000..15b72ef --- /dev/null +++ b/WOKA/Assets/Assets.xcassets/Karaoke/KaraokePause.imageset/Contents.json @@ -0,0 +1,26 @@ +{ + "images" : [ + { + "filename" : "Pause.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "Pause@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "Pause@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "template-rendering-intent" : "template" + } +} diff --git a/WOKA/Assets/Assets.xcassets/Karaoke/KaraokePause.imageset/pause.png b/WOKA/Assets/Assets.xcassets/Karaoke/KaraokePause.imageset/pause.png new file mode 100644 index 0000000000000000000000000000000000000000..f5ced19226063deea26cd671621ae47447d82451 GIT binary patch literal 560 zcmV-00?+-4P)Px$>PbXFR5(wy)yb=mQ5?td*EObCE91(FL=+3t-n11Z_QnNE#gc{b4?roF#L}!N zWWmbPRMwPCm*=DJ(c|7LKe)iH@J@r-QM+5?(6-yrLBqhig`GVO=Ea5Qgj8o@d8c%C$!zP z6gfDjERNOL>tCMGL>^f{ugZWYb#^!#ErtO-C|AFfJbPIU-rh|X&n8z$R^W9mYtS6N ziuDL^QqRvp|6jv~7}MNJQf?NoxplYVmE>&ctUc6OaTu2>X=kvi@(>#mig0c>=vi#< z9f+mJaIh?1)>-kW^JY07m+UAGlpzgz9yp1ol zG_lX~9E$^;U(ghHGMnHBdJ_A3&^uUz20ekj1&!-rr8ySm$HFc_4>4^VpdS*VKvV3` zstw1@(*F|Egl)XCe-1lG)@hQ|%Htk()evcQdIT2-sngc?|JqT}-`F~;_5SSY{k;FS z_tWz$`@J7`o3%@7O3fW$O0|N2iOt>f%aj^9PXo+6&A~sd%QYVY9yL#!a({xa#kLw6 y2}wrW=W?-4{u`zE+sWStkM)h3j`xFnqrL;kS*4QvN{S=^0000Px(TuDShR9HvVnOn$?Sro^APK6=Ll|#wliXk~%$SFePRBmPzmrl(%gt(zxC?(`D zBd1Ff#f31_%;c0D3Xx25;dJ3}r3{iY&tGe4fBW0d`#kUK^YZOdzWwgK_J6Ov4*#{D z7Sujk0WE;HB}KFbJ^=4Zu5YkR2UR;-8o=lZ3gAw#_ooO`vDNP3r~J&yk7r1714N?q)YJpNt)$UO@d^@mVSFkpmqP z5!#$&RJW%OW3Nd06$d&dC)|8%jp}@1JJaldHk+q!HqO*6!js$S_ZaYnNfpMYfbS_( z=}LL}yG@}nVgA~rME-EE1SwI4DgrH<*ea%ZM~yU#5mlmj>X4i&pn0lZRnpW-^F*F! zgfvfroY{!1{#)XK3mDTAHEhWm@k<%Ph`O6774c30Li zoM$FbuLgvg9`j?6@zXodkoE5aX4R>svp-}0bE;|SgclHzR?Q;KYJ9CGnKY?{^V-fS z)g%iw>o&FkSa0ob?|{_OG>hAgYMZMUAb)TLRn>M(fgO}hs`08I?Bh!sxra^OwJ&Yt zhMpRB*VI5*3XG_+HLhO1IK|&~K$En_^T29e@m8Qm0mA_0@YKhK2f#&ZZd{0JGtY>r z@Yi6jsA-iFkoWmUZS&OU8Px)Z%IT!RCr$Pn@6ZDRS<^1r((dIGq^A=1ar;-6@3W$o-1{0K-~z6IU|VR!n_j2 zfFdex6m!C?m=FvL!HhX#*8UznkGVbFeY(%-nd$q+T3zn+>8koqs`{&X0W&TOX54?K z0l;R!hQQjus`&)`0(=L20em{iNf|c)>jMV>2LihR+W@Nt9Q+A*A9x9PG8_LC@b$Pr z83zEX07n5Q0*3=DBpUw@@B(mK2H;(Q0Cgr^0OuEO)}Prnf{>0M^I@k{x3#n!=d3f&GB*L%N#);34-&5BGe? zH_rqEF$1YeX#&7y`Dq_g*vH>51};efzvfQijV39^=lJ%N=g!22!F z{EF$XDfI5ZI+388L~W5JYTp*eR{@Z6@EI!{U2_G=37F>_R}9N%Id32rP$m*64`yf5 zK9L}J7O%R=l(9b<qhSQe{2>unX{75dcZf$5Xv8xmo&l3uupNz9qLg*P!wH12Y1EzM5D3 z55Vw#o%t=WYo5cW?t*!H2yO~|lIs0DIRxb*%z5UV0nXeH!0L%0^nC?X215Eh)1j~c z+yKbTq)6Xaz_oc3$4DsbKNbV`qS-{%z|A+o_RJ6vY0 zHMK($RzaTucsR>%vgy-JF;S>&!p(_Sv$`iApmS%G%c2gj}fWsHv$98XmS51 zBUL9Uw75kPY4Kk}0QkE_1WRKvBHeAWArD_B+h(=RT}(Q8XK9Ex&zCu ztIH$N?%ObX80{n*kx+Tuy}VuDylH9AyLnUBpKSr~`TcX2C?zgvX>X^Gd+*zm|NQw8WRVE474BD4oIv`Y=f@o~->boZUP@*)#Yx<%t02t`%78Sn2UjSG{Kaj$?$`4O#W<^lK*lH3qb+@olS P00000NkvXXu0mjf>4=?y literal 0 HcmV?d00001 diff --git a/WOKA/Audio Books/AudioBookDetailsVC.swift b/WOKA/Audio Books/AudioBookDetailsVC.swift index 7e68046..4a218e4 100644 --- a/WOKA/Audio Books/AudioBookDetailsVC.swift +++ b/WOKA/Audio Books/AudioBookDetailsVC.swift @@ -31,7 +31,7 @@ class AudioBookDetailsVC : UIViewController{ var audioData : ListenAudioListingDM.AudioDatum? - var continueAudioData : ContinueAudioListDM.ResultData? + var continueAudioData : ListenAudioListingDM.AudioDatum? override func viewDidLoad() { super.viewDidLoad() diff --git a/WOKA/Audio Books/AudioBookHomeVC.swift b/WOKA/Audio Books/AudioBookHomeVC.swift index f8cf55c..2b86148 100644 --- a/WOKA/Audio Books/AudioBookHomeVC.swift +++ b/WOKA/Audio Books/AudioBookHomeVC.swift @@ -73,7 +73,7 @@ class AudioBookHomeVC: UIViewController { } @IBAction func listenAudioBtnTapped(_ sender: LocalisedElementsButton) { - let data = vm.audioListData[vm.indexToLoad] + guard let data = vm.headerData else{return} var playerItems = [JwPlayerItemCreate]() if AuthFunc.shareInstance.getDefaultLanguage() == .english{ if let englishData = data.contentMoreDetails?.filter({$0.languageMasterID == 1}).first, let url = englishData.url{ @@ -148,13 +148,13 @@ extension AudioBookHomeVC : TableViewSRC{ } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let data = vm.audioListData[indexPath.row] + /* Updated the top header data */ - vm.indexToLoad = indexPath.row - vm.setInitialData() - - let data = vm.audioListData[indexPath.row] + vm.headerData = data + vm.setHeaderData() let sb = UIStoryboard(name: K.StoryBoard.audioBooks, bundle: nil) let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.AudioBooks.audioBookDetailsVC) as! AudioBookDetailsVC @@ -187,11 +187,8 @@ extension AudioBookHomeVC : CollectionViewSRC{ func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { let data = vm.continueWatchingData[indexPath.row] - - if let audioListIndex = vm.audioListData.firstIndex(where:{$0.id == data.id}){ - vm.indexToLoad = audioListIndex - vm.setInitialData() - } + vm.headerData = data + vm.setHeaderData() let sb = UIStoryboard(name: K.StoryBoard.audioBooks, bundle: nil) let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.AudioBooks.audioBookDetailsVC) as! AudioBookDetailsVC diff --git a/WOKA/Audio Books/AudioBookHomeVM.swift b/WOKA/Audio Books/AudioBookHomeVM.swift index 7bce370..9868463 100644 --- a/WOKA/Audio Books/AudioBookHomeVM.swift +++ b/WOKA/Audio Books/AudioBookHomeVM.swift @@ -11,9 +11,12 @@ import Alamofire class AudioBookHomeVM{ weak var vc : AudioBookHomeVC! - var continueWatchingData = [ContinueAudioListDM.ResultData]() + var continueWatchingData = [ListenAudioListingDM.AudioDatum]() var audioListData = [ListenAudioListingDM.AudioDatum]() - var indexToLoad = 0 + + var headerData : ListenAudioListingDM.AudioDatum? + +// var indexToLoad = 0 var pageNo = 0 func initView(){ @@ -34,21 +37,21 @@ class AudioBookHomeVM{ self.vc.tableHeight.constant = self.vc.audioListingTableView.contentSize.height } - func setInitialData(){ + func setHeaderData(){ // if indexToLoad > continueWatchingData.count { // return // } - let data = audioListData[indexToLoad] + guard let headerData else{return} - if let url = data.thumbnailPath{ + if let url = headerData.thumbnailPath{ self.vc.headerImage.imageURL(url, color: .white) } if AuthFunc.shareInstance.getDefaultLanguage() == .english{ - let englishData = data.contentMoreDetails?.filter({$0.languageMasterID == 1}).first + let englishData = headerData.contentMoreDetails?.filter({$0.languageMasterID == 1}).first vc.headerTitleLabel.text = englishData?.title }else{ - let hindiData = data.contentMoreDetails?.filter({$0.languageMasterID == 2}).first + let hindiData = headerData.contentMoreDetails?.filter({$0.languageMasterID == 2}).first vc.headerTitleLabel.text = hindiData?.title } } @@ -109,7 +112,7 @@ class AudioBookHomeVM{ } } - func getShowListing(){ + func getShowListing(isBtnClick : Bool = false){ // Utilities.startProgressHUD() let headers : HTTPHeaders = ["access-token" : AuthFunc.shareInstance.getAccessToken()] let params : Parameters = ["api_version" : "v2", @@ -137,8 +140,10 @@ class AudioBookHomeVM{ self.vc.tableHeight.constant = self.vc.audioListingTableView.contentSize.height + 100 self.vc.audioListingTableView.layoutIfNeeded() self.vc.tableHeight.constant = self.vc.audioListingTableView.contentSize.height - self.indexToLoad = 0 - self.setInitialData() + if !isBtnClick{ + self.headerData = self.audioListData.first + self.setHeaderData() + } self.stopShimmer() self.vc.loadMoreActivityIndicator.stopAnimating() diff --git a/WOKA/Audio Books/ContinueAudioCell.swift b/WOKA/Audio Books/ContinueAudioCell.swift index 8b266f3..8d04d28 100644 --- a/WOKA/Audio Books/ContinueAudioCell.swift +++ b/WOKA/Audio Books/ContinueAudioCell.swift @@ -32,7 +32,7 @@ class ContinueAudioCell: UICollectionViewCell { shimmerView.stopShimmer() } - func setAudioData(data: ContinueAudioListDM.ResultData){ + func setAudioData(data: ListenAudioListingDM.AudioDatum){ //heart.fill , heart , hand.thumbsup.fill , hand.thumbsup if AuthFunc.shareInstance.getDefaultLanguage() == .english{ audioBookTitle.text = data.contentMoreDetails?.filter({$0.languageMasterID == 1}).first?.title diff --git a/WOKA/Audio Books/ContinueAudioListDM.swift b/WOKA/Audio Books/ContinueAudioListDM.swift index e2e38f3..0839cf9 100644 --- a/WOKA/Audio Books/ContinueAudioListDM.swift +++ b/WOKA/Audio Books/ContinueAudioListDM.swift @@ -9,7 +9,7 @@ import Foundation // MARK: - ContinueAudioListDM struct ContinueAudioListDM: Codable { - let result: [ResultData]? + let result: [ListenAudioListingDM.AudioDatum]? let totalRecords: Int? enum CodingKeys: String, CodingKey { diff --git a/WOKA/Audio Books/ListenAudioListingDM.swift b/WOKA/Audio Books/ListenAudioListingDM.swift index b962ab6..8051fed 100644 --- a/WOKA/Audio Books/ListenAudioListingDM.swift +++ b/WOKA/Audio Books/ListenAudioListingDM.swift @@ -28,7 +28,7 @@ struct ListenAudioListingDM: Codable { let languageMasterID: Int? let genderMasterID, audioDuration, mediaID: String? let contentMoreDetails: [ContentMoreDetail]? -// let userVideoView: [JSONAny]? + let userVideoView: [UserVideoView]? let categoryData: [CategoryDatum]? // let ageRangeData, genderData: [JSONAny]? var markAsFavourite, isLiked: Bool? @@ -47,7 +47,7 @@ struct ListenAudioListingDM: Codable { case audioDuration = "audio_duration" case mediaID = "media_id" case contentMoreDetails = "content_more_details" -// case userVideoView = "user_video_view" + case userVideoView = "user_video_view" // case ageRangeData = "age_range_data" // case genderData = "gender_data" case categoryData = "category_data" @@ -59,6 +59,23 @@ struct ListenAudioListingDM: Codable { } } + // MARK: - UserVideoView + struct UserVideoView: Codable { + let id, userID, postID, postType: Int? + let totalWatchedDuration, lastWatchedLeft: String? + let categoryID: Int? + + enum CodingKeys: String, CodingKey { + case id + case userID = "user_id" + case postID = "post_id" + case postType = "post_type" + case totalWatchedDuration = "total_watched_duration" + case lastWatchedLeft = "last_watched_left" + case categoryID = "category_id" + } + } + // MARK: - CategoryDatum struct CategoryDatum: Codable { let id: Int? @@ -90,58 +107,4 @@ struct ListenAudioListingDM: Codable { case tagsKeywords = "tags_keywords" } } - } - -// -//{ -// "id": 6, -// "title": "DADAGIRI KI AISI KI TAISE", -// "description": "

Kalu and Chitta are the two big bullies of the school who don't stop at troubling anyone. They steal someone's food and bully someone. ADI and his friends can't take it all. They go to seek help from the wise sage, Piku Baba. What clever method did Piku Baba tell Kalu and Chitta to teach them a lesson? Has Kalu and Chitta's bullying come to an end? Can ADI and his crew stop them? Listen to this funny story to find out.

", -// "thumbnail_path": "https://wokaland.com/admin/storage/app/public/uploads/Listen/64b2bdf9d277d.png?d=1719904091", -// "audio_url": "https://content.jwplatform.com/videos/tUJ8m9W0-Ysj2G4DQ.mp4", -// "category_master_id": "11", -// "age_range_master_id": "0", -// "tags_keyword": "0", -// "release_date": "2023-07-15 00:00:00", -// "language_master_id": 1, -// "gender_master_id": "0", -// "audio_duration": "00:07:25", -// "media_id": "", -// "content_more_details": [ -// { -// "id": 831, -// "content_id": 6, -// "post_type": 7, -// "language_master_id": 1, -// "title": "DADAGIRI KI AISI KI TAISE", -// "description": "

Kalu and Chitta are the two big bullies of the school who don't stop at troubling anyone. They steal someone's food and bully someone. ADI and his friends can't take it all. They go to seek help from the wise sage, Piku Baba. What clever method did Piku Baba tell Kalu and Chitta to teach them a lesson? Has Kalu and Chitta's bullying come to an end? Can ADI and his crew stop them? Listen to this funny story to find out.

", -// "url": "https://content.jwplatform.com/videos/tUJ8m9W0-Ysj2G4DQ.mp4", -// "tags_keywords": "0" -// }, -// { -// "id": 832, -// "content_id": 6, -// "post_type": 7, -// "language_master_id": 2, -// "title": "दादागिरी की ऐसी की तैसी", -// "description": "

कालू और चिट्टा स्कूल के दो बड़े बदमाश हैं जो किसी को भी सताने से बाज़ नहीं आते। किसी का वे खाना चुरा लेते हैं और किसी के ऊपर दादागिरी जमाते रहते हैं। आदि और उसके दोस्त यह सब सहन नहीं कर पा रहे हैं। वे ज्ञानी साधु, पीकू बाबा से मदद माँगने जाते हैं। कालू और चिट्ठा को सबक सिखानेके लिए। पीकू बाबा ने उन्हें कौन सा खुफिया तरीका बताया? क्या कालू और चिट्टा की दादागिरी ख़त्म हुई? क्या आदि और उसका दल उन्हें रोक पाते हैं? पता लगाने के लिए यह मज़ेदार कहानी सुनो।

", -// "url": "https://content.jwplatform.com/videos/tUJ8m9W0-Ysj2G4DQ.mp4", -// "tags_keywords": "0" -// } -// ], -// "user_video_view": [], -// "category_data": [ -// { -// "id": 11, -// "category_name": "Audio" -// } -// ], -// "age_range_data": [], -// "gender_data": [], -// "mark_as_favourite": false, -// "is_liked": false, -// "views_count": 4763, -// "likes_count": 20, -// "bookmark_count": 15 -// } diff --git a/WOKA/Games/Controller/GamesListVC.swift b/WOKA/Games/Controller/GamesListVC.swift index d4e0ea7..fb3c70c 100644 --- a/WOKA/Games/Controller/GamesListVC.swift +++ b/WOKA/Games/Controller/GamesListVC.swift @@ -18,6 +18,9 @@ class GamesListVC: UIViewController { @IBOutlet weak var headerTitleLabel: UILabel! @IBOutlet weak var gamesLoadingView: ShimmerEffectView! + @IBOutlet weak var loadMoreBtn: LocalisedElementsButton! + @IBOutlet weak var loadMoreActivityIndicator: UIActivityIndicatorView! + var vm = GamesListVM() override func viewDidLoad() { @@ -51,6 +54,8 @@ class GamesListVC: UIViewController { vm.updateTableHeight() } + // MARK: - Tap Handler + @IBAction func gameBtnTapped(_ sender: LocalisedElementsButton) { let sb = UIStoryboard(name: K.StoryBoard.Games, bundle: nil) let vcPush = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Games.gamesWebViewVC) as! GamesWebViewVC @@ -62,6 +67,13 @@ class GamesListVC: UIViewController { vcPush.modalPresentationStyle = .fullScreen self.present(vcPush, animated: true) } + + @IBAction func loadMoreBtnTapped(_ sender: LocalisedElementsButton) { + loadMoreBtn.isHidden = true + vm.pageNo += 1 + loadMoreActivityIndicator.startAnimating() + vm.getGamesListing(isBtnClick: true) + } } // MARK: - TableView DataSource , Delegates diff --git a/WOKA/Games/Games.storyboard b/WOKA/Games/Games.storyboard index 6da1737..f173a03 100644 --- a/WOKA/Games/Games.storyboard +++ b/WOKA/Games/Games.storyboard @@ -99,7 +99,7 @@ - + @@ -154,6 +196,8 @@ + + diff --git a/WOKA/Games/ViewModel/GamesListVM.swift b/WOKA/Games/ViewModel/GamesListVM.swift index 7c891a2..78519e1 100644 --- a/WOKA/Games/ViewModel/GamesListVM.swift +++ b/WOKA/Games/ViewModel/GamesListVM.swift @@ -14,6 +14,9 @@ class GamesListVM{ var gameData = [GamesListDM.GameDatum]() var indexToLoad = 0 + var pageNo = 0 + var stopFetch = false + func initView(){ setupCell() let color1 = #colorLiteral(red: 0.8, green: 0.6078431373, blue: 0.1098039216, alpha: 1) @@ -63,9 +66,13 @@ class GamesListVM{ // MARK: - Get Games Data - func getGamesListing(){ + func getGamesListing(isBtnClick : Bool = false){ let headers : HTTPHeaders = ["access-token" : AuthFunc.shareInstance.getAccessToken()] - NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Games.game_listing, method: .post,headers: headers) { [weak self](result : Result, NetworkManager.APIError>) in + let params : Parameters = ["api_version" : "v2", + "start" : pageNo, + "limit": 5] + + NetworkManager.shareInstance.apiRequest(url: APIEndPoints.Games.game_listing, method: .post,parameters: params,headers: headers) { [weak self](result : Result, NetworkManager.APIError>) in switch result{ case .success(let data): guard let self else{ @@ -78,18 +85,34 @@ class GamesListVM{ Error */ Utilities.dismissProgressHUD() - vc.toast(msg: data.message ?? "Unrecognised error" , time: 2) + self.vc.loadMoreActivityIndicator.stopAnimating() + self.vc.loadMoreActivityIndicator.hidesWhenStopped = true +// vc.toast(msg: data.message ?? "Unrecognised error" , time: 2) case 1: Utilities.dismissProgressHUD() guard let data = data.data?.gameData else{return} - self.gameData.removeAll() - self.gameData = data + self.gameData.append(contentsOf: data) self.vc.gamesListingTableView.reloadData() self.vc.tableHeight.constant = self.vc.gamesListingTableView.contentSize.height + 100 self.vc.gamesListingTableView.layoutIfNeeded() self.vc.tableHeight.constant = self.vc.gamesListingTableView.contentSize.height - self.setHeaderData() + + if !isBtnClick{ + setHeaderData() + } + self.stopShimmer() + + self.vc.loadMoreActivityIndicator.stopAnimating() + self.vc.loadMoreActivityIndicator.hidesWhenStopped = true + + if self.gameData.count.isMultiple(of: 5) && !self.stopFetch{ + // if not multiple of 10, means more data can be there, show more btn + self.vc.loadMoreBtn.isHidden = false + }else{ + self.stopFetch = true + self.vc.loadMoreBtn.isHidden = true + } default: break } diff --git a/WOKA/Karaoke/Controller/JWKaraokePlayerVC.swift b/WOKA/Karaoke/Controller/JWKaraokePlayerVC.swift index 6fddab7..13b2e2e 100644 --- a/WOKA/Karaoke/Controller/JWKaraokePlayerVC.swift +++ b/WOKA/Karaoke/Controller/JWKaraokePlayerVC.swift @@ -46,7 +46,6 @@ class JWKaraokePlayerVC: JWPlayerViewController, JWPlayerViewControllerDelegate //Disable Picture in Picture playerView.allowsPictureInPicturePlayback = false playerView.captionStyle = .none - self.view.bringSubviewToFront(outerStack) self.view.bringSubviewToFront(backButton) setupKaraoke() @@ -96,7 +95,6 @@ class JWKaraokePlayerVC: JWPlayerViewController, JWPlayerViewControllerDelegate self.interfaceBehavior = .hidden guard let audioRecorder = audioRecorder else { return } audioRecorder.record() - } func stopRecording() { @@ -146,11 +144,11 @@ class JWKaraokePlayerVC: JWPlayerViewController, JWPlayerViewControllerDelegate // Export the mixed audio let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! - let filePath = documentsDirectory.appendingPathComponent("mixedAudio.m4a") + let fileName = "\((self.videoTitle?.replacingOccurrences(of: " ", with: "").replacingOccurrences(of: ".", with: "") ?? "Audio") + Date().timeIntervalSince1970.toString()).m4a" + let filePath = documentsDirectory.appendingPathComponent(fileName) deleteFileIfExist(at: filePath) mixedAudioURL = filePath -// mixedAudioURL = documentsDirectory.appendingPathComponent("mixedAudio.m4a") guard let exportSession = AVAssetExportSession(asset: composition, presetName: AVAssetExportPresetAppleM4A) else { return } exportSession.outputURL = mixedAudioURL @@ -162,6 +160,7 @@ class JWKaraokePlayerVC: JWPlayerViewController, JWPlayerViewControllerDelegate Utilities.dismissProgressHUD() DispatchQueue.main.async { self.playBtn.isEnabled = true + self.downloadRecordingBtn.isEnabled = true } @@ -304,12 +303,21 @@ class JWKaraokePlayerVC: JWPlayerViewController, JWPlayerViewControllerDelegate @IBAction func playBtnTapped(_ sender: LocalisedElementsButton) { if !isPlaying { playMixedAudio() - self.interfaceBehavior = .normal - self.interfaceBehavior = .hidden sender.setTitle("Pause", for: .normal) + sender.setImage(UIImage(named: "KaraokePause"), for: .normal) + + // Disable Recording while playing, hide controls for jwplayer + self.interfaceBehavior = .hidden + self.startRecordBtn.isEnabled = false + self.downloadRecordingBtn.isEnabled = false } else { - self.interfaceBehavior = .normal sender.setTitle("Play", for: .normal) + sender.setImage(UIImage(named: "PlayButtonSmall"), for: .normal) + + // Disable Recording while playing, hide controls for jwplayer + self.interfaceBehavior = .normal + self.startRecordBtn.isEnabled = true + self.downloadRecordingBtn.isEnabled = true } isPlaying.toggle() @@ -317,36 +325,55 @@ class JWKaraokePlayerVC: JWPlayerViewController, JWPlayerViewControllerDelegate self.player.pause() print("Play") } + func playMixedAudio() { guard let mixedAudioURL = mixedAudioURL else { return } - - do { - - let documentsDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! + do { + let documentsDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! let destinationURL = documentsDirectoryURL.appendingPathComponent("xyze.m4a") - do { - - try FileManager.default.copyItem(at: mixedAudioURL, to: destinationURL) - - } catch - let error as NSError { print(error.localizedDescription)} - + // Check if file already exists + if FileManager.default.fileExists(atPath: destinationURL.path) { + // Delete the existing file + try FileManager.default.removeItem(at: destinationURL) + } + + // Copy the new file + try FileManager.default.copyItem(at: mixedAudioURL, to: destinationURL) + + // Play the audio let playerKAraoke = AVPlayer(url: destinationURL) + + // Adding a completion handler to check if the player starts playing + let playerObserver = playerKAraoke.addPeriodicTimeObserver(forInterval: CMTime(seconds: 1, preferredTimescale: 1), queue: .main) { time in + print("Playing audio at time: \(time.seconds)") + } + + // Observing when playback finishes + NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: playerKAraoke.currentItem, queue: .main) { _ in + print("Audio finished playing") + // Remove observer + playerKAraoke.removeTimeObserver(playerObserver) + } + playerKAraoke.volume = 1.0 playerKAraoke.play() + print("Audio is playing...") + // Uncomment this block if you need to configure the audio session and play using AVAudioPlayer + /* + // Configure the audio session + let audioSession = AVAudioSession.sharedInstance() + try audioSession.setCategory(.playAndRecord, mode: .default, options: [.defaultToSpeaker]) + try audioSession.setActive(true) + + let audioPlayer = try AVAudioPlayer(contentsOf: mixedAudioURL) + audioPlayer.volume = 1.0 + audioPlayer.play() + */ -// // Configure the audio session -// let audioSession = AVAudioSession.sharedInstance() -// try audioSession.setCategory(.playAndRecord, mode: .default, options: [.defaultToSpeaker]) -// try audioSession.setActive(true) -// -// let audioPlayer = try AVAudioPlayer(contentsOf: mixedAudioURL) -// audioPlayer.volume = 1.0 -// audioPlayer.play() } catch { - print("Error playing mixed audio: \(error.localizedDescription)") + print("Error: \(error.localizedDescription)") } } diff --git a/WOKA/Karaoke/Karaoke.storyboard b/WOKA/Karaoke/Karaoke.storyboard index dd80233..d6a16ba 100644 --- a/WOKA/Karaoke/Karaoke.storyboard +++ b/WOKA/Karaoke/Karaoke.storyboard @@ -833,7 +833,7 @@ - + + + + + + + + + + + + @@ -244,6 +286,8 @@ + +