对收藏,下载状态的刷新代码添加
This commit is contained in:
parent
273ee3155a
commit
c8cf604c59
@ -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?) {
|
||||||
|
|||||||
@ -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) {
|
||||||
//执行预加载
|
//执行预加载
|
||||||
|
|||||||
@ -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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user