diff --git a/relax.offline.mp3.music.xcodeproj/project.pbxproj b/relax.offline.mp3.music.xcodeproj/project.pbxproj index 1bd432f..4a101a8 100644 --- a/relax.offline.mp3.music.xcodeproj/project.pbxproj +++ b/relax.offline.mp3.music.xcodeproj/project.pbxproj @@ -1563,7 +1563,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1.0.5.1; + CURRENT_PROJECT_VERSION = 1.0.6.1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = T93S37G27F; GENERATE_INFOPLIST_FILE = YES; @@ -1582,7 +1582,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.5; + MARKETING_VERSION = 1.0.6; PRODUCT_BUNDLE_IDENTIFIER = relax.offline.mp3.music; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1604,7 +1604,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1.0.5.1; + CURRENT_PROJECT_VERSION = 1.0.6.1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = T93S37G27F; GENERATE_INFOPLIST_FILE = YES; @@ -1623,7 +1623,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.5; + MARKETING_VERSION = 1.0.6; PRODUCT_BUNDLE_IDENTIFIER = relax.offline.mp3.music; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; 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 484c5b9..7c151a5 100644 --- a/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_NetWorkManager.swift +++ b/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_NetWorkManager.swift @@ -63,16 +63,16 @@ class MP_NetWorkManager: NSObject { private let youTubeKeys:[String] = ["MUSIC_VIDEO_TYPE_ATV","MUSIC_VIDEO_TYPE_OMV","MUSIC_PAGE_TYPE_ALBUM","MUSIC_PAGE_TYPE_ARTIST","MUSIC_PAGE_TYPE_PLAYLIST","MUSIC_PAGE_TYPE_TRACK_LYRICS","MUSIC_PAGE_TYPE_TRACK_RELATED"] ///禁止接入IP信息组 private let banIPs:[String] = [ - "CN", - "HK", - "TW", - "JP", - "KR", - "GB", - "CH", - "BE", - "MO", - "SG" +// "CN", +// "HK", +// "TW", +// "JP", +// "KR", +// "GB", +// "CH", +// "BE", +// "MO", +// "SG" ] //网络状态 enum NetWorkStatus: String { 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 05318e9..cb1a7a9 100644 --- a/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_PlayerManager.swift +++ b/relax.offline.mp3.music/MP/Common/Tool(工具封装)/MP_PlayerManager.swift @@ -161,6 +161,8 @@ class MP_PlayerManager:NSObject{ NotificationCenter.notificationKey.add(observer: self, selector: #selector(userSwitchCurrentVideoAction(_ :)), notificationName: .positive_player_reload) //监听网络状态恢复可用 NotificationCenter.notificationKey.add(observer: self, selector: #selector(netWorkReachableAction(_ :)), notificationName: .net_switch_reachable) + //监听蓝牙设备的状态 + NotificationCenter.default.addObserver(self, selector: #selector(handleAudioSessionRouteChangeAction(_ :)), name: AVAudioSession.routeChangeNotification, object: nil) //设置一个秒为刻度的时间值 let interval:CMTime = .init(seconds: 1, preferredTimescale: .init(1)) //为播放器添加运行时主线程每秒触发事件 @@ -257,6 +259,13 @@ class MP_PlayerManager:NSObject{ //暂停计时器 timer?.suspend() timerType = .Suspend + guard times != 0 else { + return + } + 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 ?? "") } ///网络状态恢复正常 @@ -271,6 +280,30 @@ class MP_PlayerManager:NSObject{ playState = .Playing } } + ///监听到音视频路由发生变化 + @objc private func handleAudioSessionRouteChangeAction(_ notification: Notification) { + guard let info = notification.userInfo, let reasonValue = info[AVAudioSessionRouteChangeReasonKey] as? UInt, let reason = AVAudioSession.RouteChangeReason(rawValue:reasonValue) else { + return + } + switch reason { + case .newDeviceAvailable:// 新设备连接 + let session = AVAudioSession.sharedInstance() + for output in session.currentRoute.outputs where output.portType == .headphones { + print("耳机已连接") + } + //继续运行 + case .oldDeviceUnavailable:// 设备断开 + if let previousRoute = info[AVAudioSessionRouteChangePreviousRouteKey] as? AVAudioSessionRouteDescription { + for output in previousRoute.outputs where output.portType == .headphones { + print("耳机已断开") + } + } + //暂停当前播放 + pause() + default: + break + } + } //实现KVO监听 override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { @@ -305,16 +338,12 @@ class MP_PlayerManager:NSObject{ cacheLoadTimes() case "playbackLikelyToKeepUp"://是否存在足够的数据开始播放 if let playbackLikelyToKeepUp = change?[.newKey] as? Bool, playbackLikelyToKeepUp == true { - if playState != .Playing { + if playState != .Playing && playState != .Pause { //还未播放当前音乐,启动播放 player.play() playState = .Playing //暂停计时器,并获取延时值 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 ?? "") //执行开始播放闭包 if startActionBlock != nil { startActionBlock!()