diff --git a/relax.offline.mp3.music.xcodeproj/project.pbxproj b/relax.offline.mp3.music.xcodeproj/project.pbxproj index 33655fa..6c36f58 100644 --- a/relax.offline.mp3.music.xcodeproj/project.pbxproj +++ b/relax.offline.mp3.music.xcodeproj/project.pbxproj @@ -612,9 +612,9 @@ CBAFCA3C2C0A10500054500E /* JsonStructs(js文件结构) */ = { isa = PBXGroup; children = ( + CBAFCA322C0A10500054500E /* MPPositive_JsonBrowse.swift */, CBAFCA302C0A10500054500E /* MPPositive_JsonArtist.swift */, CBAFCA312C0A10500054500E /* MPPositive_JsonArtistMore.swift */, - CBAFCA322C0A10500054500E /* MPPositive_JsonBrowse.swift */, CBAFCA332C0A10500054500E /* MPPositive_JsonListAlbum.swift */, CBAFCA342C0A10500054500E /* MPPositive_JsonLyrics.swift */, CBAFCA352C0A10500054500E /* MPPositive_JsonNext.swift */, @@ -682,8 +682,8 @@ CBAFCA5E2C0A10500054500E /* ViewModels */ = { isa = PBXGroup; children = ( - CBAFCA572C0A10500054500E /* ListViewModels */, CBAFCA5D2C0A10500054500E /* LoadViewModels */, + CBAFCA572C0A10500054500E /* ListViewModels */, ); path = ViewModels; sourceTree = ""; @@ -692,8 +692,8 @@ isa = PBXGroup; children = ( CBAFCA3C2C0A10500054500E /* JsonStructs(js文件结构) */, - CBAFCA472C0A10500054500E /* Models */, CBAFCA5E2C0A10500054500E /* ViewModels */, + CBAFCA472C0A10500054500E /* Models */, ); path = Models; sourceTree = ""; @@ -822,13 +822,13 @@ CBAFCA9F2C0A10500054500E /* Search */ = { isa = PBXGroup; children = ( - CBAFCA982C0A10500054500E /* MPPositive_SearchResultPreviewShowView.swift */, - CBAFCA992C0A10500054500E /* MPPositive_SearchResultShowTableViewCell.swift */, - CBAFCA9A2C0A10500054500E /* MPPositive_SearchResultsShowView.swift */, - CBAFCA9B2C0A10500054500E /* MPPositive_SearchResultTypeShowView.swift */, - CBAFCA9C2C0A10500054500E /* MPPositive_SearchSuggestionItemTableViewCell.swift */, - CBAFCA9D2C0A10500054500E /* MPPositive_SearchSuggestionsView.swift */, CBAFCA9E2C0A10500054500E /* MPPositive_SearchTagCollectionViewCell.swift */, + CBAFCA9D2C0A10500054500E /* MPPositive_SearchSuggestionsView.swift */, + CBAFCA9A2C0A10500054500E /* MPPositive_SearchResultsShowView.swift */, + CBAFCA982C0A10500054500E /* MPPositive_SearchResultPreviewShowView.swift */, + CBAFCA9B2C0A10500054500E /* MPPositive_SearchResultTypeShowView.swift */, + CBAFCA992C0A10500054500E /* MPPositive_SearchResultShowTableViewCell.swift */, + CBAFCA9C2C0A10500054500E /* MPPositive_SearchSuggestionItemTableViewCell.swift */, ); path = Search; sourceTree = ""; @@ -1541,9 +1541,10 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 4; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = T93S37G27F; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = relax.offline.mp3.music/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = Musiclax; @@ -1580,9 +1581,10 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; - CODE_SIGN_STYLE = Manual; + CODE_SIGN_IDENTITY = "Apple Development"; + CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 4; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = T93S37G27F; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = relax.offline.mp3.music/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = Musiclax; diff --git a/relax.offline.mp3.music/MP/Common/Base(公用基类)/Controllers/MP_LunchViewController.swift b/relax.offline.mp3.music/MP/Common/Base(公用基类)/Controllers/MP_LunchViewController.swift index 7f1316f..2b0c7e7 100644 --- a/relax.offline.mp3.music/MP/Common/Base(公用基类)/Controllers/MP_LunchViewController.swift +++ b/relax.offline.mp3.music/MP/Common/Base(公用基类)/Controllers/MP_LunchViewController.swift @@ -31,68 +31,68 @@ class MP_LunchViewController: UIViewController { timer.add(to: RunLoop.current, forMode: .common) //获取idfa _ = requestTrackingAuthorization(self) - MP_AnalyticsManager.shared.getOpenStatus { [weak self] open in - guard let self = self else {return} - if open { - //根据ip值确定进入那个页面 - MP_NetWorkManager.shared.requestIPInfo { statu in - if statu == true { - //允许进入b面 - print("BLog") - self.completionBlock = { - DispatchQueue.main.async { - [weak self] in - guard let self = self else {return} - //停止计时器 - timer.isPaused = true - //加载完毕,判断并跳转 - accessAppdelegate.switch_positive() - } - } - }else { - print("ALog") - //打开A面 - self.completionBlock = { - DispatchQueue.main.async { - [weak self] in - guard let self = self else {return} - //停止计时器 - timer.isPaused = true - //加载完毕,判断并跳转 - accessAppdelegate.switch_aSide() - } - } - } - } - }else { - print("ALog") - //打开A面 - completionBlock = { - DispatchQueue.main.async { - [weak self] in - guard let self = self else {return} - //停止计时器 - timer.isPaused = true - //加载完毕,判断并跳转 - accessAppdelegate.switch_aSide() - } - } - } - } - //启动计时器 - timer.isPaused = false -// self.completionBlock = { -// DispatchQueue.main.async { -// [weak self] in -// guard let self = self else {return} -// //停止计时器 -// timer.isPaused = true -// //加载完毕,判断并跳转 -// accessAppdelegate.switch_positive() -// //获取首页 -// MPPositive_BrowseLoadViewModel.shared.reloadBrowseLists() +// MP_AnalyticsManager.shared.getOpenStatus { [weak self] open in +// guard let self = self else {return} +// if open { +// //根据ip值确定进入那个页面 +// MP_NetWorkManager.shared.requestIPInfo { statu in +// if statu == true { +// //允许进入b面 +// print("BLog") +// self.completionBlock = { +// DispatchQueue.main.async { +// [weak self] in +// guard let self = self else {return} +// //停止计时器 +// timer.isPaused = true +// //加载完毕,判断并跳转 +// accessAppdelegate.switch_positive() +// } +// } +// }else { +// print("ALog") +// //打开A面 +// self.completionBlock = { +// DispatchQueue.main.async { +// [weak self] in +// guard let self = self else {return} +// //停止计时器 +// timer.isPaused = true +// //加载完毕,判断并跳转 +// accessAppdelegate.switch_aSide() +// } +// } +// } +// } +// }else { +// print("ALog") +// //打开A面 +// completionBlock = { +// DispatchQueue.main.async { +// [weak self] in +// guard let self = self else {return} +// //停止计时器 +// timer.isPaused = true +// //加载完毕,判断并跳转 +// accessAppdelegate.switch_aSide() +// } +// } // } // } + //启动计时器 + timer.isPaused = false + self.completionBlock = { + DispatchQueue.main.async { + [weak self] in + guard let self = self else {return} + //停止计时器 + timer.isPaused = true + //加载完毕,判断并跳转 + accessAppdelegate.switch_positive() + //获取首页 + MPPositive_BrowseLoadViewModel.shared.reloadBrowseLists() + } + } } deinit { //销毁计时器 diff --git a/relax.offline.mp3.music/MP/Common/Macro(宏定义与全局量)/Macro.swift b/relax.offline.mp3.music/MP/Common/Macro(宏定义与全局量)/Macro.swift index 154af25..450de94 100644 --- a/relax.offline.mp3.music/MP/Common/Macro(宏定义与全局量)/Macro.swift +++ b/relax.offline.mp3.music/MP/Common/Macro(宏定义与全局量)/Macro.swift @@ -98,7 +98,7 @@ func improveDataforLycirsAndRelated(_ song:MPPositive_SongItemModel, completion: } } ///调用player对资源路径和封面路径补全 -func improveDataforResouceAndCover(_ song:MPPositive_SongItemModel, completion:@escaping((([String],[Int],[String]), [String]?) -> Void)) { +func improveDataforResouceAndCover(_ song:MPPositive_SongItemModel, completion:@escaping((([String],[Int],[String])?, [String]?) -> Void)) { //单曲补全需要调用player接口 MP_NetWorkManager.shared.requestAndroidPlayer(song.videoId, playlistId: "") { resourceUrls, coverUrls in completion(resourceUrls,coverUrls) diff --git a/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_AnalyticsManager.swift b/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_AnalyticsManager.swift index a80e042..7a0fc9c 100644 --- a/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_AnalyticsManager.swift +++ b/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_AnalyticsManager.swift @@ -59,7 +59,8 @@ class MP_AnalyticsManager: NSObject { super.init() Crashlytics.crashlytics().log(app_crash) //为配置设置默认值 -// remoteConfig.setDefaults(["openStatus":false as NSObject]) + remoteConfig.setDefaults(["versionCode":app_Version as NSObject, + "enter":false as NSObject]) } //MARK: - A/B func getOpenStatus(_ completion:@escaping ((Bool) -> Void)) { diff --git a/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_NetWorkManager.swift b/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_NetWorkManager.swift index 8ad8f14..2e4f7df 100644 --- a/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_NetWorkManager.swift +++ b/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_NetWorkManager.swift @@ -19,7 +19,29 @@ class MP_NetWorkManager: NSObject { static let shared = MP_NetWorkManager() //MARK: - 网络请求会话 ///会话实例 - private let MPSession = Alamofire.Session(interceptor: MP_CustomRetrier()) + private lazy var MPSession:Session = { + let configuration = URLSessionConfiguration.af.default + //最多同时执行4条 + configuration.timeoutIntervalForRequest = 30 + configuration.timeoutIntervalForResource = 30 + return Alamofire.Session(configuration: configuration, interceptor: MP_CustomRetrier()) + }() + ///播放资源会话实例 + private lazy var PlayerSeesion:Session = { + let configuration = URLSessionConfiguration.af.default + configuration.timeoutIntervalForRequest = 30 + configuration.timeoutIntervalForResource = 30 + //最多同时执行4条 + configuration.httpMaximumConnectionsPerHost = 4 + return Alamofire.Session(configuration: configuration, interceptor: MP_CustomRetrier()) + }() + ///播放资源请求记录组 + private var playerRequests: [PlayerRequest] = [] + ///播放资源请求结构体 + struct PlayerRequest { + let request: DataRequest + let onCancel: (() -> Void) + } //MARK: - API接口 ///IP获取 private let iPInfo:String = "https://api.tikustok.com/app/common/getIPInfo" @@ -631,7 +653,7 @@ extension MP_NetWorkManager { //MARK: - 请求player播放资源 /// 请求Player(单曲/视频)播放资源 /// - Parameter item: 请求的预览实体 - func requestAndroidPlayer(_ videoId: String, playlistId: String, completion:@escaping ((([String],[Int],[String]), [String]?) -> Void)){ + func requestAndroidPlayer(_ videoId: String, playlistId: String, completion:@escaping ((([String],[Int],[String])?, [String]?) -> Void)){ //拼接出player路径 let path = header+point+player //设置url @@ -650,12 +672,6 @@ extension MP_NetWorkManager { "clientVersion": "\(day.month).\(day.toString(.custom("dd"))).1", "platform":"MOBILE", "browserVersion":"125.0.0.0", -// "userAgent": -// "clientName": "ANDROID_MUSIC", -// "clientVersion": "5.28.1", -// "platform": "MOBILE", -// "androidSdkVersion":"30", -// "userAgent": "com.google.android.apps.youtube.music/5.28.1 (Linux; U; Android 11) gzip" ] ] @@ -665,11 +681,20 @@ extension MP_NetWorkManager { completion(resourceUlrs, coverUrls) } } - private func requestAndroidPostPlayer(_ url:URL, parameters:Parameters, completion:@escaping((([String],[Int],[String]), [String]?) -> Void)) { + private func requestAndroidPostPlayer(_ url:URL, parameters:Parameters, completion:@escaping((([String],[Int],[String])?, [String]?) -> Void)) { + //删除已完成或者取消的请求 + playerRequests = playerRequests.filter({$0.request.task?.state == .running}) + // 检查活跃请求的数量,如果达到上限,则取消第一个请求 + if playerRequests.count >= 4, let requestToCancel = playerRequests.first { + requestToCancel.request.cancel() + //执行请求取消 + requestToCancel.onCancel() + playerRequests.removeFirst() + print("取消多余的Player资源请求: \(requestToCancel)") + } //发送post请求 - MPSession.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseDecodable(of: JsonAndroidPlayer.self) { [weak self] (response) in + let request = PlayerSeesion.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default).responseDecodable(of: JsonAndroidPlayer.self) { [weak self] (response) in guard let self = self else {return} - switch response.result { case .success(let value): parsingAndroidPlayer(value) { resourceUlrs, coverUrls in @@ -680,6 +705,10 @@ extension MP_NetWorkManager { handleError(url, error: error) } } + // 将新请求添加到追踪数组 + playerRequests.append(.init(request: request, onCancel: { + completion(nil,nil) + })) } // func requestPlayer(_ videoId: String, playlistId: String, completion:@escaping ((([String],[Float],[String]), [String]?) -> Void)){ // //拼接出player路径 diff --git a/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_PlayerManager.swift b/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_PlayerManager.swift index 77936bc..bb4a882 100644 --- a/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_PlayerManager.swift +++ b/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_PlayerManager.swift @@ -69,15 +69,36 @@ class MP_PlayerManager:NSObject{ private var queue:DispatchQueue? ///load模块 var loadPlayer:MPPositive_PlayerLoadViewModel!{ - didSet{ - if loadPlayer != nil { - //当load模块接受到新值的时候,发出通知,提醒底部模块状态切换 - NotificationCenter.notificationKey.post(notificationName: .pup_bottom_show) - }else { - //用户清空了load模块,隐藏播放器 - NotificationCenter.notificationKey.post(notificationName: .player_delete_list) - playState = .Null - player.pause() + willSet{ + DispatchQueue.main.async { + [weak self] in + guard let self = self else {return} + guard loadPlayer != nil else { + if newValue != nil { + //当load模块接受到新值的时候,发出通知,提醒底部模块状态切换 + NotificationCenter.notificationKey.post(notificationName: .pup_bottom_show) + } + return + } + if newValue != nil { + //当load模块接受到新值的时候,发出通知,提醒底部模块状态切换 + NotificationCenter.notificationKey.post(notificationName: .pup_bottom_show) + }else { + //用户清空了load模块,隐藏播放器 + NotificationCenter.notificationKey.post(notificationName: .player_delete_list) + playState = .Null + player.pause() + center?.playCommand.removeTarget(self) + center?.pauseCommand.removeTarget(self) + center?.nextTrackCommand.removeTarget(self) + center?.previousTrackCommand.removeTarget(self) + center = nil + do { + try AVAudioSession.sharedInstance().setActive(false) + } catch { + print("Error deactivating audio session: \(error)") + } + } } } } @@ -194,10 +215,8 @@ class MP_PlayerManager:NSObject{ if startAction != nil { startActionBlock = startAction } - //启动播放器 - let newItem = loadPlayer.currentVideo.resourcePlayerItem //覆盖播放器原有的playerItem - player.replaceCurrentItem(with: newItem) + player.replaceCurrentItem(with: loadPlayer?.currentVideo?.resourcePlayerItem) if center == nil { setCommandCenter() } @@ -206,11 +225,11 @@ class MP_PlayerManager:NSObject{ //对当前播放PlayerItem设置监听状态 if loadPlayer.currentVideo?.isKVO == false { //准备状态 - newItem?.addObserver(self, forKeyPath: "status", options: [.old,.new], context: nil) + loadPlayer?.currentVideo?.resourcePlayerItem?.addObserver(self, forKeyPath: "status", options: [.old,.new], context: nil) //当前缓冲值 - newItem?.addObserver(self, forKeyPath: "loadedTimeRanges", options: [.old,.new], context: nil) + loadPlayer?.currentVideo?.resourcePlayerItem?.addObserver(self, forKeyPath: "loadedTimeRanges", options: [.old,.new], context: nil) //是否具备足够播放的能力 - newItem?.addObserver(self, forKeyPath: "playbackLikelyToKeepUp", options: [.old,.new], context: nil) + loadPlayer?.currentVideo?.resourcePlayerItem?.addObserver(self, forKeyPath: "playbackLikelyToKeepUp", options: [.old,.new], context: nil) loadPlayer.currentVideo.isKVO = true //将进度回归为0 player.seek(to: .zero) @@ -262,7 +281,7 @@ class MP_PlayerManager:NSObject{ //判断当前播放器是否在播放当前音乐中 if playState != .Playing { //当statuVlaue值等于playerItem准备播放的值,说明已经准备好播放 - print("当前音乐-\(loadPlayer.currentVideo?.title ?? "") 已经准备好播放") + print("当前音乐-\(loadPlayer?.currentVideo?.title ?? "") 已经准备好播放") // if playState != .Playing { // player.play() // playState = .Playing @@ -295,8 +314,8 @@ class MP_PlayerManager:NSObject{ suspendTimer() let times = Int(self.times) let msTimes = times*1000 - MP_AnalyticsManager.shared.player_b_delay_actionAction(loadPlayer.currentVideo?.song.videoId ?? "", videoname: loadPlayer.currentVideo?.title ?? "", artistname: loadPlayer.currentVideo?.song.shortBylineText ?? "", delay: "\(msTimes)ms") - MP_AnalyticsManager.shared.player_b_success_actionAction(loadPlayer.currentVideo?.song.videoId ?? "", videoname: loadPlayer.currentVideo?.title ?? "", artistname: loadPlayer.currentVideo?.song.shortBylineText ?? "") + MP_AnalyticsManager.shared.player_b_delay_actionAction(loadPlayer?.currentVideo?.song.videoId ?? "", videoname: loadPlayer?.currentVideo?.title ?? "", artistname: loadPlayer?.currentVideo?.song.shortBylineText ?? "", delay: "\(msTimes)ms") + MP_AnalyticsManager.shared.player_b_success_actionAction(loadPlayer?.currentVideo?.song.videoId ?? "", videoname: loadPlayer?.currentVideo?.title ?? "", artistname: loadPlayer?.currentVideo?.song.shortBylineText ?? "") //执行开始播放闭包 if startActionBlock != nil { startActionBlock!() diff --git a/relax.offline.mp3.music/MP/MPPositive/Models/ViewModels/ListViewModels/MPPositive_SongViewModel.swift b/relax.offline.mp3.music/MP/MPPositive/Models/ViewModels/ListViewModels/MPPositive_SongViewModel.swift index a191823..62c63ce 100644 --- a/relax.offline.mp3.music/MP/MPPositive/Models/ViewModels/ListViewModels/MPPositive_SongViewModel.swift +++ b/relax.offline.mp3.music/MP/MPPositive/Models/ViewModels/ListViewModels/MPPositive_SongViewModel.swift @@ -44,6 +44,7 @@ class MPPositive_SongViewModel: NSObject { configure() } deinit { + print("\(title ?? "")已经销毁了") resourcePlayerItem = nil resourcePlayerAsset = nil resourcePlayerURL = nil diff --git a/relax.offline.mp3.music/MP/MPPositive/Models/ViewModels/LoadViewModels/MPPositive_PlayerLoadViewModel.swift b/relax.offline.mp3.music/MP/MPPositive/Models/ViewModels/LoadViewModels/MPPositive_PlayerLoadViewModel.swift index a1a172b..23c536e 100644 --- a/relax.offline.mp3.music/MP/MPPositive/Models/ViewModels/LoadViewModels/MPPositive_PlayerLoadViewModel.swift +++ b/relax.offline.mp3.music/MP/MPPositive/Models/ViewModels/LoadViewModels/MPPositive_PlayerLoadViewModel.swift @@ -15,7 +15,7 @@ class MPPositive_PlayerLoadViewModel: NSObject { ///当前播放音乐ViewModel var currentVideo:MPPositive_SongViewModel!{ willSet{ - DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { + DispatchQueue.main.asyncAfter(deadline: .now()) { [weak self] in guard let self = self else {return} if newValue != nil { @@ -123,9 +123,11 @@ class MPPositive_PlayerLoadViewModel: NSObject { //没有下载过 //补全资源路径组和封面路径组 improveDataforResouceAndCover(item) {[weak self] resourceUrls, coverUrls in - item.resourceUrls = resourceUrls.0 - item.itags = resourceUrls.1 - item.mimeTypes = resourceUrls.2 + if let resourceUrls = resourceUrls { + item.resourceUrls = resourceUrls.0 + item.itags = resourceUrls.1 + item.mimeTypes = resourceUrls.2 + } item.coverUrls = coverUrls //补全完成,转化为ViewModel,并添加进listViewVideos self?.listViewVideos.append(.init(item)) @@ -147,9 +149,11 @@ class MPPositive_PlayerLoadViewModel: NSObject { //当前歌曲不能播放,需要重新配置资源 improveDataforResouceAndCover(currentVideo.song) {[weak self] resourceUrls, coverUrls in guard let self = self else {return} - currentVideo.song.resourceUrls = resourceUrls.0 - currentVideo.song.itags = resourceUrls.1 - currentVideo.song.mimeTypes = resourceUrls.2 + if let resourceUrls = resourceUrls { + currentVideo.song.resourceUrls = resourceUrls.0 + currentVideo.song.itags = resourceUrls.1 + currentVideo.song.mimeTypes = resourceUrls.2 + } //成功更新资源,将重新补完的歌曲,放进listViewVideos中 listViewVideos.forEach({ item in if item.song.videoId == self.currentVideo.song.videoId { diff --git a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Base(基类,导航栏,标签栏)/MPPositive_MoreSongOperationsViewController.swift b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Base(基类,导航栏,标签栏)/MPPositive_MoreSongOperationsViewController.swift index 59335b4..9a099ba 100644 --- a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Base(基类,导航栏,标签栏)/MPPositive_MoreSongOperationsViewController.swift +++ b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Base(基类,导航栏,标签栏)/MPPositive_MoreSongOperationsViewController.swift @@ -75,6 +75,7 @@ class MPPositive_MoreSongOperationsViewController: UIViewController { } var removeBlock:(() -> Void)? var disMissBlock:(() -> Void)? + var collectionBlock:(() -> Void)? init(_ song:MPPositive_SongItemModel) { super.init(nibName: nil, bundle: nil) DispatchQueue.main.async { @@ -169,6 +170,9 @@ class MPPositive_MoreSongOperationsViewController: UIViewController { MPPositive_LoadCoreModel.shared.reloadCollectionSongViewModel(nil) MP_AnalyticsManager.shared.player_b_love_clickAction(song.videoId, videoname: song.title ?? "", artistname: song.shortBylineText ?? "") } + if collectionBlock != nil { + collectionBlock!() + } } } //MARK: - tableView diff --git a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Center(个人曲库页)/MPPositive_LoveSongsViewController.swift b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Center(个人曲库页)/MPPositive_LoveSongsViewController.swift index 7270b2b..1844e53 100644 --- a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Center(个人曲库页)/MPPositive_LoveSongsViewController.swift +++ b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Center(个人曲库页)/MPPositive_LoveSongsViewController.swift @@ -83,9 +83,11 @@ extension MPPositive_LoveSongsViewController: UITableViewDataSource, UITableView group.enter() //补全资源路径组和封面路径组 improveDataforResouceAndCover(first) {[weak self] resourceUrls, coverUrls in - first.resourceUrls = resourceUrls.0 - first.itags = resourceUrls.1 - first.mimeTypes = resourceUrls.2 + if let resourceUrls = resourceUrls { + first.resourceUrls = resourceUrls.0 + first.itags = resourceUrls.1 + first.mimeTypes = resourceUrls.2 + } first.coverUrls = coverUrls group.leave() } @@ -99,6 +101,9 @@ extension MPPositive_LoveSongsViewController: UITableViewDataSource, UITableView moreVC.disMissBlock = { self?.reload() } + moreVC.collectionBlock = { + self?.reload() + } moreVC.transitioningDelegate = self moreVC.modalPresentationStyle = .custom self?.present(moreVC, animated: true) diff --git a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Home(首页,各项列表页,艺术家页)/MPPositive_ArtistShowViewController.swift b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Home(首页,各项列表页,艺术家页)/MPPositive_ArtistShowViewController.swift index 8028730..a35c5a6 100644 --- a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Home(首页,各项列表页,艺术家页)/MPPositive_ArtistShowViewController.swift +++ b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Home(首页,各项列表页,艺术家页)/MPPositive_ArtistShowViewController.swift @@ -250,9 +250,11 @@ extension MPPositive_ArtistShowViewController: JXPagingViewDelegate{ group.enter() //补全资源路径组和封面路径组 improveDataforResouceAndCover(first) {[weak self] resourceUrls, coverUrls in - first.resourceUrls = resourceUrls.0 - first.itags = resourceUrls.1 - first.mimeTypes = resourceUrls.2 + if let resourceUrls = resourceUrls { + first.resourceUrls = resourceUrls.0 + first.itags = resourceUrls.1 + first.mimeTypes = resourceUrls.2 + } first.coverUrls = coverUrls group.leave() } diff --git a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Home(首页,各项列表页,艺术家页)/MPPositive_ListShowViewController.swift b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Home(首页,各项列表页,艺术家页)/MPPositive_ListShowViewController.swift index 48bdad4..e8c2d41 100644 --- a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Home(首页,各项列表页,艺术家页)/MPPositive_ListShowViewController.swift +++ b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Home(首页,各项列表页,艺术家页)/MPPositive_ListShowViewController.swift @@ -320,9 +320,11 @@ extension MPPositive_ListShowViewController: UITableViewDataSource, UITableViewD group.enter() //补全资源路径组和封面路径组 improveDataforResouceAndCover(first) {[weak self] resourceUrls, coverUrls in - first.resourceUrls = resourceUrls.0 - first.itags = resourceUrls.1 - first.mimeTypes = resourceUrls.2 + if let resourceUrls = resourceUrls { + first.resourceUrls = resourceUrls.0 + first.itags = resourceUrls.1 + first.mimeTypes = resourceUrls.2 + } first.coverUrls = coverUrls group.leave() } diff --git a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Player(播放器)/MPPositive_PlayerListShowViewController.swift b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Player(播放器)/MPPositive_PlayerListShowViewController.swift index 44e97e2..f90791e 100644 --- a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Player(播放器)/MPPositive_PlayerListShowViewController.swift +++ b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Player(播放器)/MPPositive_PlayerListShowViewController.swift @@ -88,6 +88,9 @@ extension MPPositive_PlayerListShowViewController: UITableViewDataSource, UITabl func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { //播放选中音乐 dismiss(animated: true) { + guard MP_PlayerManager.shared.loadPlayer?.songVideos[indexPath.row].videoId != MP_PlayerManager.shared.loadPlayer?.currentVideo?.song.videoId else { + return + } //更新播放音乐 MP_PlayerManager.shared.loadPlayer.improveData(MP_PlayerManager.shared.loadPlayer.songVideos[indexPath.row].videoId) } diff --git a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Player(播放器)/MPPositive_RecommendViewController.swift b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Player(播放器)/MPPositive_RecommendViewController.swift index c3829eb..0a9ca3f 100644 --- a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Player(播放器)/MPPositive_RecommendViewController.swift +++ b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Player(播放器)/MPPositive_RecommendViewController.swift @@ -259,9 +259,11 @@ extension MPPositive_RecommendViewController: JXSegmentedListContainerViewDataSo group.enter() //补全资源路径组和封面路径组 improveDataforResouceAndCover(first) {[weak self] resourceUrls, coverUrls in - first.resourceUrls = resourceUrls.0 - first.itags = resourceUrls.1 - first.mimeTypes = resourceUrls.2 + if let resourceUrls = resourceUrls { + first.resourceUrls = resourceUrls.0 + first.itags = resourceUrls.1 + first.mimeTypes = resourceUrls.2 + } first.coverUrls = coverUrls group.leave() } diff --git a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Search(搜索页)/MPPositive_SearchResultShowViewController.swift b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Search(搜索页)/MPPositive_SearchResultShowViewController.swift index 13c9a99..1de2d2e 100644 --- a/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Search(搜索页)/MPPositive_SearchResultShowViewController.swift +++ b/relax.offline.mp3.music/MP/MPPositive/ViewControllers/Search(搜索页)/MPPositive_SearchResultShowViewController.swift @@ -148,9 +148,11 @@ class MPPositive_SearchResultShowViewController: MPPositive_BaseViewController, group.enter() //补全资源路径组和封面路径组 improveDataforResouceAndCover(first) {[weak self] resourceUrls, coverUrls in - first.resourceUrls = resourceUrls.0 - first.itags = resourceUrls.1 - first.mimeTypes = resourceUrls.2 + if let resourceUrls = resourceUrls { + first.resourceUrls = resourceUrls.0 + first.itags = resourceUrls.1 + first.mimeTypes = resourceUrls.2 + } first.coverUrls = coverUrls group.leave() } diff --git a/relax.offline.mp3.music/MP/MPPositive/Views/Player/MPPositive_PlayerListShowTableViewCell.swift b/relax.offline.mp3.music/MP/MPPositive/Views/Player/MPPositive_PlayerListShowTableViewCell.swift index f6e7156..ae6e055 100644 --- a/relax.offline.mp3.music/MP/MPPositive/Views/Player/MPPositive_PlayerListShowTableViewCell.swift +++ b/relax.offline.mp3.music/MP/MPPositive/Views/Player/MPPositive_PlayerListShowTableViewCell.swift @@ -40,6 +40,8 @@ class MPPositive_PlayerListShowTableViewCell: UITableViewCell { coverImageView.kf.setImage(with: URL(string: song.reviewUrls?.first ?? ""), placeholder: placeholderImage) titleLabel.text = song.title subtitleLabel.text = song.shortBylineText + //当前音乐不可移除 + removeBtn.isHidden = (song.videoId == MP_PlayerManager.shared.loadPlayer?.currentVideo?.song.videoId) } } var removeBlock:(() -> Void)? diff --git a/relax.offline.mp3.music/MP/MPPositive/Views/Player/MPPositive_PlayerSilder.swift b/relax.offline.mp3.music/MP/MPPositive/Views/Player/MPPositive_PlayerSilder.swift index 63ca37b..3a1711d 100644 --- a/relax.offline.mp3.music/MP/MPPositive/Views/Player/MPPositive_PlayerSilder.swift +++ b/relax.offline.mp3.music/MP/MPPositive/Views/Player/MPPositive_PlayerSilder.swift @@ -8,6 +8,10 @@ import UIKit ///b面播放器进度条(展示缓存效果,聚焦时进行尺寸变化) class MPPositive_PlayerSilder: UISlider { + /// 触控扩展边距 + var hitTestEdgeInsets: UIEdgeInsets = UIEdgeInsets(top: -20, left: -20, bottom: -20, right: -20) + /// 原始的Slider大小 + var originalFrame: CGRect? //滑块图片 var thumbImage:UIImage = .init(named: "Player_Slider'logo")! //滑轨槽高度 @@ -26,6 +30,11 @@ class MPPositive_PlayerSilder: UISlider { super.init(frame: frame) setUpLayout() } + override func awakeFromNib() { + super.awakeFromNib() + print("调整Slider大小") + originalFrame = self.frame + } required init?(coder: NSCoder) { super.init(coder: coder) @@ -122,4 +131,16 @@ class MPPositive_PlayerSilder: UISlider { override func trackRect(forBounds bounds: CGRect) -> CGRect { return CGRect(x: 0, y: 0, width: bounds.width, height: self.trackHeight) } + //MARK: - 交互代码 + //当用户点击时 + override func point(inside point: CGPoint, with event: UIEvent?) -> Bool { + //对Slider添加一个边距范围 + let largerFrame: CGRect = self.bounds.inset(by: hitTestEdgeInsets) + //检索当前点击点是否在边距范围内 + let isInside = largerFrame.contains(point) + + return true + } + //当用户焦点汇聚到slider + } diff --git a/relax.offline.mp3.music/MP/MPPositive/Views/Search/MPPositive_SearchResultShowTableViewCell.swift b/relax.offline.mp3.music/MP/MPPositive/Views/Search/MPPositive_SearchResultShowTableViewCell.swift index 52926bc..98a415b 100644 --- a/relax.offline.mp3.music/MP/MPPositive/Views/Search/MPPositive_SearchResultShowTableViewCell.swift +++ b/relax.offline.mp3.music/MP/MPPositive/Views/Search/MPPositive_SearchResultShowTableViewCell.swift @@ -13,6 +13,7 @@ class MPPositive_SearchResultShowTableViewCell: UITableViewCell { let imageView:UIImageView = .init() imageView.contentMode = .scaleAspectFill imageView.layer.masksToBounds = true + imageView.layer.cornerRadius = 10*width return imageView }() private lazy var titleLabel:UILabel = createLabel(font: .systemFont(ofSize: 14*width, weight: .regular), textColor: .white, textAlignment: .left) diff --git a/relax.offline.mp3.music/MP/MPPositive/Views/Search/MPPositive_SearchResultTypeShowView.swift b/relax.offline.mp3.music/MP/MPPositive/Views/Search/MPPositive_SearchResultTypeShowView.swift index 283ac09..81860a6 100644 --- a/relax.offline.mp3.music/MP/MPPositive/Views/Search/MPPositive_SearchResultTypeShowView.swift +++ b/relax.offline.mp3.music/MP/MPPositive/Views/Search/MPPositive_SearchResultTypeShowView.swift @@ -56,6 +56,8 @@ class MPPositive_SearchResultTypeShowView: UIView, JXSegmentedListContainerViewL } var scrollBlock:(() -> Void)? var moreBlock:((MPPositive_SearchResultItemViewModel) -> Void)? + //选中内容 + var chooseItemBlock:((MPPositive_SearchResultItemViewModel) -> Void)? init(frame: CGRect, list:MPPositive_SearchResultListViewModel) { super.init(frame: frame) backgroundColor = .init(hex: "1A1A1A") @@ -118,4 +120,9 @@ extension MPPositive_SearchResultTypeShowView:UITableViewDataSource, UITableView func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 0 } + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + if chooseItemBlock != nil { + chooseItemBlock!(sectionList.allItemViews[indexPath.row]) + } + } } diff --git a/relax.offline.mp3.music/MP/MPPositive/Views/Search/MPPositive_SearchResultsShowView.swift b/relax.offline.mp3.music/MP/MPPositive/Views/Search/MPPositive_SearchResultsShowView.swift index bdf678a..39f2eef 100644 --- a/relax.offline.mp3.music/MP/MPPositive/Views/Search/MPPositive_SearchResultsShowView.swift +++ b/relax.offline.mp3.music/MP/MPPositive/Views/Search/MPPositive_SearchResultsShowView.swift @@ -173,6 +173,15 @@ extension MPPositive_SearchResultsShowView: JXSegmentedListContainerViewDataSour moreBlock!(itemView) } } + showView.chooseItemBlock = { + [weak self] item in + guard let self = self else { + return + } + if chooseItemBlock != nil { + chooseItemBlock!(item) + } + } return showView } }