1.2.2 广告最终策略调整

This commit is contained in:
QinFendeZhou 2024-09-27 16:34:46 +08:00
parent 6ea3f5943c
commit c48641fc10
17 changed files with 89 additions and 59 deletions

View File

@ -74,7 +74,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
MP_DownloadManager.shared.session.completionHandler = completionHandler
}
}
//
///
func setAudioSupport(){
//
let session = AVAudioSession.sharedInstance()
@ -90,19 +90,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
//
UIApplication.shared.beginReceivingRemoteControlEvents()
}
func setAudioResume() {
//
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(.playAndRecord, mode: .default, options: [ .allowAirPlay, .allowBluetoothA2DP,.defaultToSpeaker])
//
try session.setActive(true)
print("恢复会话")
} catch {
print("Failed to set type:\(error.localizedDescription)")
}
}
///
///
func setAudioStop() {
//
let session = AVAudioSession.sharedInstance()
@ -114,18 +102,29 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
print("Failed to set type:\(error.localizedDescription)")
}
}
///
///
func setAudioActive() {
//
let session = AVAudioSession.sharedInstance()
do {
//
try session.setCategory(.playAndRecord, mode: .default, options: [ .allowAirPlay, .allowBluetoothA2DP,.defaultToSpeaker])
try session.setActive(true)
print("恢复会话")
if session.category != .playAndRecord || session.categoryOptions != [ .allowAirPlay, .allowBluetoothA2DP,.defaultToSpeaker] {
if session.category != .playAndRecord {
print("音频会话状态发生变动")
}else {
print("音频会话类型发生变动")
}
try session.setCategory(.playAndRecord, mode: .default, options: [ .allowAirPlay, .allowBluetoothA2DP,.defaultToSpeaker])
try session.setActive(true)
print("重新设置音频会话模型")
}else {
try session.setActive(true)
print("恢复会话")
}
} catch {
print("Failed to set type:\(error.localizedDescription)")
}
//
NotificationCenter.notificationKey.post(notificationName: .player_is_continua)
}
//
private func ActiveDaysCalculation() {

View File

@ -121,6 +121,8 @@ extension NotificationCenter{
case search_gride_reload
///广
case library_native_success
///
case player_is_continua
}
}
}

View File

@ -567,7 +567,7 @@ func postUpdateReminder(_ observe:UIViewController) {
observe.present(alter, animated: true)
}
///线
func playOfflineSongs() {
func playOfflineSongs(_ videoId:String) {
if MPPositive_LoadCoreModel.shared.loadViewModels.isEmpty == false {
MP_HUD.text("You are in offline mode".localizableString(), delay: 2.0, completion: nil)
//线
@ -594,7 +594,15 @@ func playOfflineSongs() {
item.relatedID = song.loadItem.relatedID
array.append(item)
}
if let currentVideo = MPPositive_LoadCoreModel.shared.loadViewModels.first {
//videoIdloadModels
if let currentVideo = MPPositive_LoadCoreModel.shared.loadViewModels.first(where: {$0.loadItem.videoId == videoId}) {
let lodaViewModel = MPPositive_PlayerLoadViewModel(array, currentVideoId: currentVideo.loadItem.videoId ?? "")
lodaViewModel.improveData(currentVideo.loadItem.videoId ?? "")
//
MP_PlayerManager.shared.setPlayType(.normal)
MP_PlayerManager.shared.loadPlayer = lodaViewModel
MP_AnalyticsManager.shared.player_b_listAction()
}else if let currentVideo = MPPositive_LoadCoreModel.shared.loadViewModels.first {
let lodaViewModel = MPPositive_PlayerLoadViewModel(array, currentVideoId: currentVideo.loadItem.videoId ?? "")
lodaViewModel.improveData(currentVideo.loadItem.videoId ?? "")
//

View File

@ -81,6 +81,9 @@ class MP_ADSimpleManager: NSObject {
override init() {
super.init()
NotificationCenter.notificationKey.add(observer: self, selector: #selector(netWorkReachableAction(_:)), notificationName: .net_switch_reachable)
DispatchQueue.main.async {
GADMobileAds.sharedInstance().audioVideoManager.audioSessionIsApplicationManaged = true
}
}
deinit{
NotificationCenter.default.removeObserver(self)
@ -89,11 +92,15 @@ class MP_ADSimpleManager: NSObject {
func isAdMuted() {
DispatchQueue.main.async {
if MP_PlayerManager.shared.getPlayState() == .Playing {
GADMobileAds.sharedInstance().audioVideoManager.audioSessionIsApplicationManaged = true
GADMobileAds.sharedInstance().applicationMuted = true
if GADMobileAds.sharedInstance().applicationMuted == false {
GADMobileAds.sharedInstance().applicationMuted = true
GADMobileAds.sharedInstance().applicationVolume = 0.1
print("播放中,静音广告")
}
}else {
GADMobileAds.sharedInstance().audioVideoManager.audioSessionIsApplicationManaged = false
GADMobileAds.sharedInstance().applicationMuted = false
GADMobileAds.sharedInstance().applicationVolume = 1
print("没有播放,不需要静音广告")
}
}
}
@ -101,8 +108,8 @@ class MP_ADSimpleManager: NSObject {
func isAdSounded() {
DispatchQueue.main.async {
if GADMobileAds.sharedInstance().applicationMuted == true {
GADMobileAds.sharedInstance().audioVideoManager.audioSessionIsApplicationManaged = false
GADMobileAds.sharedInstance().applicationMuted = false
print("加载广告时恢复广告声音配置")
}
}
}

View File

@ -1544,11 +1544,11 @@ class MP_AdMobManager: NSObject, GADAudioVideoManagerDelegate, GADFullScreenCont
//MARK: - 广 GADAudioVideoManagerDelegate
//广
func audioVideoManagerWillPlayVideo(_ audioVideoManager: GADAudioVideoManager) {
print("广告将会播放视频")
// print("广")
}
//广
func audioVideoManagerDidPauseAllVideo(_ audioVideoManager: GADAudioVideoManager) {
print("广告暂停播放视频")
// print("广")
}
//广
func audioVideoManagerWillPlayAudio(_ audioVideoManager: GADAudioVideoManager) {

View File

@ -251,6 +251,8 @@ class MP_PlayerManager:NSObject{
NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying(_ :)), name: .AVPlayerItemDidPlayToEndTime, object: player.currentItem)
//
NotificationCenter.notificationKey.add(observer: self, selector: #selector(userSwitchCurrentVideoAction(_ :)), notificationName: .positive_player_reload)
//
NotificationCenter.notificationKey.add(observer: self, selector: #selector(sessionIsActiveAction(_ :)), notificationName: .player_is_continua)
//
NotificationCenter.notificationKey.add(observer: self, selector: #selector(netWorkReachableAction(_ :)), notificationName: .net_switch_reachable)
//
@ -489,6 +491,18 @@ class MP_PlayerManager:NSObject{
videoLayer.player = player
}
}
//
@objc private func sessionIsActiveAction(_ sender:Notification) {
//
if let current = loadPlayer?.currentVideo, playState == .Playing, player.timeControlStatus == .paused {
//
DispatchQueue.main.async {
[weak self] in
self?.player.play()
print("播放器播放状态被某些因素强制暂停了,需要恢复播放")
}
}
}
///
@objc private func netWorkReachableAction(_ sender:Notification) {

View File

@ -513,10 +513,11 @@ extension MPPositive_LoveSongsViewController: UITableViewDataSource, UITableView
MPPositive_Debouncer.shared.call {
[weak self] in
guard let self = self else {return}
// guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
// MP_HUD.text("Bad connection~".localizableString(), delay: 2.0, completion: nil)
// return
// }
let currentVideo = isSearchStyle ? searchSongs[indexPath.row]:showSongs[indexPath.row]
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs(currentVideo.collectionSong.videoId ?? "")
return
}
MP_AnalyticsManager.shared.song_clickAction("Love Song")
//
MP_PlayerManager.shared.loadPlayer = nil
@ -537,7 +538,6 @@ extension MPPositive_LoveSongsViewController: UITableViewDataSource, UITableView
item.relatedID = song.collectionSong.relatedID
array.append(item)
}
let currentVideo = isSearchStyle ? searchSongs[indexPath.row]:showSongs[indexPath.row]
let lodaViewModel = MPPositive_PlayerLoadViewModel(array, currentVideoId: currentVideo.collectionSong.videoId ?? "")
lodaViewModel.improveData(currentVideo.collectionSong.videoId ?? "")
//

View File

@ -592,7 +592,7 @@ extension MPPositive_HomeViewController: UITableViewDataSource, UITableViewDeleg
[weak self] in
guard let self = self else {return}
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs()
playOfflineSongs(item.browseItem.videoId ?? "")
return
}
MP_AnalyticsManager.shared.song_clickAction("Home")

View File

@ -249,7 +249,7 @@ class MPPositive_ListShowViewController: MPPositive_BaseViewController, UIViewCo
[weak self] in
guard let self = self, let item = listOrAlbum.items.first else {return}
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs()
playOfflineSongs(item.browseItem.videoId ?? "")
return
}
MP_AnalyticsManager.shared.song_clickAction("List")
@ -277,7 +277,7 @@ class MPPositive_ListShowViewController: MPPositive_BaseViewController, UIViewCo
[weak self] in
guard let self = self, let item = listOrAlbum.items.randomElement() else {return}
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs()
playOfflineSongs(item.browseItem.videoId ?? "")
return
}
MP_AnalyticsManager.shared.song_clickAction("List")
@ -394,16 +394,15 @@ extension MPPositive_ListShowViewController: UITableViewDataSource, UITableViewD
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
MPPositive_Debouncer.shared.call {
[weak self] in
guard let self = self else {return}
guard let self = self, let item = listOrAlbum?.items[indexPath.row] else {return}
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs()
playOfflineSongs(item.browseItem.videoId ?? "")
return
}
MP_AnalyticsManager.shared.song_clickAction("List")
//
NotificationCenter.notificationKey.post(notificationName: .pup_player_vc)
MP_AnalyticsManager.shared.player_b_impAction()
let item = listOrAlbum.items[indexPath.row]
//next
MP_NetWorkManager.shared.requestNextList(item.browseItem.playListId ?? "", videoId: item.browseItem.videoId ?? "", clickTrackingParams: item.browseItem.clickTrackingParams){ [weak self] listSongs in
guard let self = self else {return}

View File

@ -137,9 +137,9 @@ extension MPPositive_MoreContentViewController: UICollectionViewDataSource, UICo
///
MPPositive_Debouncer.shared.call {
[weak self] in
guard let self = self else {return}
guard let self = self, let item = browseModuleList?.items[indexPath.row] else {return}
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs()
playOfflineSongs(item.browseItem.videoId ?? "")
return
}
MP_AnalyticsManager.shared.song_clickAction("MoreContent")
@ -148,7 +148,6 @@ extension MPPositive_MoreContentViewController: UICollectionViewDataSource, UICo
//
NotificationCenter.notificationKey.post(notificationName: .pup_player_vc)
MP_AnalyticsManager.shared.player_b_impAction()
let item = browseModuleList.items[indexPath.row]
//next
MP_NetWorkManager.shared.requestNextList(item.browseItem.playListId ?? "", videoId: item.browseItem.videoId ?? "", clickTrackingParams: item.browseItem.clickTrackingParams){ [weak self] listSongs in
guard let self = self else {return}

View File

@ -144,7 +144,7 @@ extension MPPositive_GrideMoodViewController: UITableViewDataSource, UITableView
[weak self] in
guard let self = self else {return}
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs()
playOfflineSongs(item.browseItem.videoId ?? "")
return
}
MP_AnalyticsManager.shared.song_clickAction("Mood")

View File

@ -273,12 +273,11 @@ extension MPPositive_ArtistShowTypeView:UITableViewDataSource, UITableViewDelega
if let first = sectionList?.itemViews.first {
switch first.browseItem.itemType {
case .single:
let item = sectionList.itemViews[indexPath.row]
MPPositive_Debouncer.shared.call {
[weak self] in
guard let self = self else {return}
guard let self = self, let item = sectionList?.itemViews[indexPath.row] else {return}
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs()
playOfflineSongs(item.browseItem.videoId ?? "")
return
}
MP_AnalyticsManager.shared.song_clickAction("Artist")

View File

@ -166,11 +166,11 @@ extension MPPositive_HomeSinglesTableViewCell:UICollectionViewDataSource, UIColl
MPPositive_Debouncer.shared.call {
[weak self] in
guard let self = self else {return}
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs()
guard let item = (self.browseViewModel?.items[indexPath.row] ?? self.personlViewModel?.items[indexPath.row]) else {
return
}
guard let item = (self.browseViewModel?.items[indexPath.row] ?? self.personlViewModel?.items[indexPath.row]) else {
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs(item.browseItem.videoId ?? "")
return
}
MP_AnalyticsManager.shared.home_b_module_clickAction(item.browseItem.pageType ?? "")

View File

@ -197,7 +197,7 @@ class MPPositive_PersonalisedRecommendationsTableViewCell: UITableViewCell, UIVi
[weak self] in
guard let self = self else {return}
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs()
playOfflineSongs(item.videoId ?? "")
return
}
MP_AnalyticsManager.shared.home_b_module_clickAction(titleLabel.text ?? "")
@ -328,7 +328,7 @@ extension MPPositive_PersonalisedRecommendationsTableViewCell:UICollectionViewDa
[weak self] in
guard let self = self else {return}
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs()
playOfflineSongs(item.browseItem.videoId ?? "")
return
}
MP_AnalyticsManager.shared.home_b_module_clickAction(item.browseItem.pageType ?? "")

View File

@ -76,16 +76,16 @@ class MPPositive_SearchResultPreviewShowView: MPPositive_BaseShowView, JXSegment
}
}
func chooseItemClick(_ item:MPPositive_SearchResultItemViewModel) {
switch item.item.itemType {
switch item.item?.itemType {
case .artist:
//
let artistVC = MPPositive_ArtistShowViewController(item.item.artistId ?? "", clickTrackingParams: item.item.clickTrackingParams ?? "")
let artistVC = MPPositive_ArtistShowViewController(item.item?.artistId ?? "", clickTrackingParams: item.item?.clickTrackingParams ?? "")
if let vc = self.parentController(ofType: MPPositive_SearchResultShowViewController.self) {
vc.navigationController?.pushViewController(artistVC, animated: true)
}
case .list:
//
let listVC = MPPositive_ListShowViewController(item.item.browseId ?? "", params: "", title: item.title ?? "", subtitle: item.subtitle ?? "", clickTrackingParams: item.item.clickTrackingParams ?? "")
let listVC = MPPositive_ListShowViewController(item.item?.browseId ?? "", params: "", title: item.title ?? "", subtitle: item.subtitle ?? "", clickTrackingParams: item.item?.clickTrackingParams ?? "")
if let vc = self.parentController(ofType: MPPositive_SearchResultShowViewController.self) {
vc.navigationController?.pushViewController(listVC, animated: true)
}
@ -94,7 +94,7 @@ class MPPositive_SearchResultPreviewShowView: MPPositive_BaseShowView, JXSegment
[weak self] in
guard let self = self else {return}
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs()
playOfflineSongs(item.item?.videoId ?? "")
return
}
MP_AnalyticsManager.shared.song_clickAction("Search")

View File

@ -46,8 +46,11 @@ class MPPositive_SearchResultTypeShowView: MPPositive_BaseShowView, JXSegmentedL
}
sectionList.completionBlock = {
[weak self] in
self?.tableView.reloadData()
self?.tableView.mj_footer?.endRefreshing()
DispatchQueue.main.async {
[weak self] in
self?.tableView.reloadData()
self?.tableView.mj_footer?.endRefreshing()
}
}
}else {
tableView.reloadData()
@ -94,7 +97,7 @@ class MPPositive_SearchResultTypeShowView: MPPositive_BaseShowView, JXSegmentedL
}
//
@objc private func footerRefresh() {
guard sectionList.continuation != nil, sectionList.itct != nil else {
guard sectionList?.continuation != nil, sectionList?.itct != nil else {
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
@ -102,7 +105,7 @@ class MPPositive_SearchResultTypeShowView: MPPositive_BaseShowView, JXSegmentedL
}
return
}
sectionList.requestSearchContinuation()
sectionList?.requestSearchContinuation()
}
func chooseItemClick(_ item:MPPositive_SearchResultItemViewModel) {
switch item.item.itemType {
@ -123,7 +126,7 @@ class MPPositive_SearchResultTypeShowView: MPPositive_BaseShowView, JXSegmentedL
[weak self] in
guard let self = self else {return}
guard MP_NetWorkManager.shared.netWorkStatu == .reachable else {
playOfflineSongs()
playOfflineSongs(item.item?.browseId ?? "")
return
}
MP_AnalyticsManager.shared.song_clickAction("Search")