46 lines
1.7 KiB
Swift
46 lines
1.7 KiB
Swift
//
|
|
// BaseViewController.swift
|
|
// MusicPlayer
|
|
//
|
|
// Created by Mr.Zhou on 2024/3/27.
|
|
//
|
|
|
|
import UIKit
|
|
///基类页面
|
|
class BaseViewController: UIViewController {
|
|
///音乐文件缺失
|
|
var nullMusicAction:ActionBlock?
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
//背景颜色黑色
|
|
view.backgroundColor = .init(hex: "#151718")
|
|
navigationController?.navigationBar.isTranslucent = true
|
|
tabBarController?.tabBar.isTranslucent = true
|
|
//隐藏导航栏
|
|
navigationController?.setNavigationBarHidden(true, animated: false)
|
|
}
|
|
//音乐文件缺失
|
|
@objc func fileMissAction(_ sender:Notification) {
|
|
DispatchQueue.main.async {
|
|
[weak self] in
|
|
//弹出删除音乐框
|
|
let alert = UIAlertController(title: "Missing Files", message: "The current music file is missing and will remove remove the music from the catalog. If you want to continue using the music file, please re-import it!", preferredStyle: .alert)
|
|
let okAction = UIAlertAction(title: "OK", style: .destructive) { [weak self] (_) in
|
|
guard let music = MPMediaCenterManager.shared.getMusic() else {
|
|
return
|
|
}
|
|
//从表中删除当前音乐实体
|
|
MusicModel.delete(music)
|
|
MPMediaCenterManager.shared.setMusic(nil)
|
|
//执行删除闭包
|
|
guard self?.nullMusicAction != nil else {
|
|
return
|
|
}
|
|
self?.nullMusicAction!()
|
|
}
|
|
alert.addAction(okAction)
|
|
self?.present(alert, animated: true)
|
|
}
|
|
}
|
|
}
|