播放器的再优化

This commit is contained in:
Mr.zhou 2024-05-22 16:41:41 +08:00
parent 26a46c83a3
commit f75ff871a2
5 changed files with 30 additions and 25 deletions

View File

@ -8,6 +8,7 @@
import UIKit
import CoreData
import AVFoundation
import Alamofire
@_exported import IQKeyboardManagerSwift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
@ -81,7 +82,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
window?.rootViewController = tabBarVC
window?.makeKeyAndVisible()
}
// MARK: - Core Data stack
lazy var persistentContainer: NSPersistentContainer = {
/*

View File

@ -37,30 +37,30 @@ class MP_NetWorkManager: NSObject {
private let search = "/search"
///YouTuBe
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"]
///
//
enum NetWorkStatus: String {
case notReachable = "网络不可用"
case unknown = "网络未知"
case reachable = "网络可用"
}
private var netWorkStatu:NetWorkStatus = .reachable{
///
private let reachabilityManager:NetworkReachabilityManager = NetworkReachabilityManager(host: "https://music.youtube.com/")!
///
var netWorkStatu:NetWorkStatus!{
willSet{
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
if netWorkStatu == .reachable, newValue == .notReachable {
print("网络不可用")
NotificationCenter.notificationKey.post(notificationName: .net_switch_notReachable)
}
//
if netWorkStatu == .notReachable, newValue == .reachable {
print("网络可用")
NotificationCenter.notificationKey.post(notificationName: .net_switch_reachable)
}
//
if netWorkStatu == .reachable, newValue == .notReachable {
print("网络不可用")
NotificationCenter.notificationKey.post(notificationName: .net_switch_notReachable)
}
//
if (netWorkStatu == .notReachable), newValue == .reachable {
print("网络可用")
NotificationCenter.notificationKey.post(notificationName: .net_switch_reachable)
}
}
}
//MARK: -
//访
private var visitorData:String?
@ -158,10 +158,8 @@ class MP_NetWorkManager: NSObject {
}
///
func requestStatusToYouTube() {
//
let reachabilityManager = NetworkReachabilityManager(host: "https://music.youtube.com/")
//ping
reachabilityManager?.startListening(onQueue: .main, onUpdatePerforming: { [weak self] status in
reachabilityManager.startListening(onQueue: .main, onUpdatePerforming: { [weak self] status in
guard let self = self else {return}
switch status {
case .unknown://
@ -173,7 +171,6 @@ class MP_NetWorkManager: NSObject {
}
})
}
}
//MARK: - API
extension MP_NetWorkManager {

View File

@ -171,10 +171,11 @@ class MP_PlayerManager:NSObject{
///
@objc private func netWorkReachableAction(_ sender:Notification) {
//
if loadPlayer.currentVideo != nil {
if loadPlayer?.currentVideo != nil {
//
let currentTime = loadPlayer.currentVideo!.resourcePlayerItem.currentTime()
//
player.seek(to: currentTime)
player.play()
playState = .Playing
}
@ -225,7 +226,6 @@ class MP_PlayerManager:NSObject{
if let playbackLikelyToKeepUp = change?[.newKey] as? Bool, playbackLikelyToKeepUp == true {
if playState != .Playing {
//
print("播放音乐-\(loadPlayer.currentVideo?.title ?? "")")
player.play()
playState = .Playing
//

View File

@ -307,7 +307,7 @@ class MPPositive_PlayerViewController: MPPositive_BaseViewController, UIViewCont
coverView.subtitleLabel.text = MP_PlayerManager.shared.loadPlayer.currentVideo?.subtitle
lyricsView.titleLabel.text = MP_PlayerManager.shared.loadPlayer.currentVideo?.title
lyricsView.subtitleLabel.text = MP_PlayerManager.shared.loadPlayer.currentVideo?.subtitle
lyricsView.lyricsLabel.text = MP_PlayerManager.shared.loadPlayer.currentVideo?.lyrics ?? "No Lyrics"
lyricsView.lyricsLabel.text = MP_PlayerManager.shared.loadPlayer.currentVideo?.lyrics?.isEmpty == true ? "No Lyrics":MP_PlayerManager.shared.loadPlayer.currentVideo?.lyrics
coverView.loadBtn.isSelected = MP_PlayerManager.shared.loadPlayer.currentVideo?.isDlownd ?? false
coverView.collectionSongBtn.isSelected = MP_PlayerManager.shared.loadPlayer.currentVideo?.isCollection ?? false
}

View File

@ -156,11 +156,19 @@ class MPPositive_PlayerCoverView: UIView {
}
//
@objc private func netWorkNotReachableAction(_ sender:Notification) {
maskNotReachableView.isHidden = false
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
maskNotReachableView.isHidden = false
}
}
//
@objc private func netWorkReachableAction(_ sender:Notification) {
maskNotReachableView.isHidden = true
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
maskNotReachableView.isHidden = true
}
}
//