对收藏,下载状态的刷新代码添加

This commit is contained in:
Mr.zhou 2024-05-21 16:01:59 +08:00
parent 273ee3155a
commit c8cf604c59
3 changed files with 15 additions and 13 deletions

View File

@ -160,8 +160,6 @@ class MP_PlayerManager:NSObject{
loadPlayer.currentVideo?.resourcePlayerItem?.addObserver(self, forKeyPath: "status", options: [.old,.new], context: nil) loadPlayer.currentVideo?.resourcePlayerItem?.addObserver(self, forKeyPath: "status", options: [.old,.new], context: nil)
// //
loadPlayer.currentVideo?.resourcePlayerItem.addObserver(self, forKeyPath: "loadedTimeRanges", options: [.old,.new], context: nil) loadPlayer.currentVideo?.resourcePlayerItem.addObserver(self, forKeyPath: "loadedTimeRanges", options: [.old,.new], context: nil)
//PlayerItem
} }
//KVO //KVO
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {

View File

@ -74,17 +74,21 @@ class MPPositive_SongViewModel: NSObject {
if song.relatedID != nil { if song.relatedID != nil {
relatedId = song.relatedID relatedId = song.relatedID
} }
// reloadCollectionAndDownLoad()
isCollection = MPPositive_CollectionSongModel.fetch(.init(format: "videoId == %@", song.videoId)).count != 0
//
isDlownd = MPPositive_DownloadItemModel.fetch(.init(format: "videoId == %@", song.videoId)).count != 0
// //
if isPloading == false { if isPloading == false {
preloadAsset(resourceAsset) preloadAsset(resourceAsset)
} }
} }
//
func reloadCollectionAndDownLoad() {
//
isCollection = MPPositive_CollectionSongModel.fetch(.init(format: "videoId == %@", song.videoId)).count != 0
//
isDlownd = MPPositive_DownloadItemModel.fetch(.init(format: "videoId == %@", song.videoId)).count != 0
}
// //
func preloadAsset(_ asset:AVURLAsset) { func preloadAsset(_ asset:AVURLAsset) {
// //

View File

@ -157,6 +157,7 @@ class MPPositive_PlayerCoverView: UIView {
MPPositive_CollectionSongModel.delete(i) MPPositive_CollectionSongModel.delete(i)
} }
} }
MP_PlayerManager.shared.loadPlayer.currentVideo.reloadCollectionAndDownLoad()
} }
}else{ }else{
self.collectionSongBtn.isSelected = true self.collectionSongBtn.isSelected = true
@ -167,6 +168,7 @@ class MPPositive_PlayerCoverView: UIView {
item.subtitle = MP_PlayerManager.shared.loadPlayer.currentVideo.subtitle item.subtitle = MP_PlayerManager.shared.loadPlayer.currentVideo.subtitle
item.coverImage = MP_PlayerManager.shared.loadPlayer.currentVideo.coverUrl item.coverImage = MP_PlayerManager.shared.loadPlayer.currentVideo.coverUrl
MPPositive_CollectionSongModel.save() MPPositive_CollectionSongModel.save()
MP_PlayerManager.shared.loadPlayer.currentVideo.reloadCollectionAndDownLoad()
} }
} }
} }
@ -204,6 +206,7 @@ class MPPositive_PlayerCoverView: UIView {
MPPositive_DownloadItemModel.save() MPPositive_DownloadItemModel.save()
DispatchQueue.main.async { DispatchQueue.main.async {
MP_PlayerManager.shared.loadPlayer.currentVideo.reloadCollectionAndDownLoad()
self?.loadBtn.setBackgroundImage(UIImage(named: "Song_Loaded'logo"), for: .normal) self?.loadBtn.setBackgroundImage(UIImage(named: "Song_Loaded'logo"), for: .normal)
self?.loadBtn.setImage(UIImage(named: ""), for: .normal) self?.loadBtn.setImage(UIImage(named: ""), for: .normal)
} }
@ -216,10 +219,7 @@ class MPPositive_PlayerCoverView: UIView {
self?.loadBtn.setBackgroundImage(UIImage(named: "Song_Unload'logo"), for: .normal) self?.loadBtn.setBackgroundImage(UIImage(named: "Song_Unload'logo"), for: .normal)
self?.loadBtn.setImage(UIImage(named: ""), for: .normal) self?.loadBtn.setImage(UIImage(named: ""), for: .normal)
} }
SVProgressHUD.showInfo(withStatus: "下载超时请重新下载") MP_HUD.text("下载超时请重新下载", delay: 1.5, completion: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
SVProgressHUD.dismiss()
}
} }
}) })
} }