Music_Player3/MusicPlayer/MP/Common/Macro(宏定义与全局量)/Macro.swift
2024-05-31 21:50:46 +08:00

210 lines
8.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Macro.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/3/25.
//
import UIKit
import Foundation
import AVFoundation
import AppTrackingTransparency
import AdSupport
@_exported import JXSegmentedView
@_exported import JXPagingView
//JXPagingListContainerViewextensionJXSegmentedViewListContainer
extension JXPagingListContainerView: JXSegmentedViewListContainer {}
//MARK: -
///
let screen_Width = UIScreen.main.bounds.width
///
let screen_Height = UIScreen.main.bounds.height
///
let width = screen_Width / 375
///
#if __IPHONE_13_0
let statusBarHeight:CGFloat = UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame.size.height
#else
let statusBarHeight:CGFloat = UIApplication.shared.statusBarFrame.size.height
#endif
///
let navAndstatusBarHeight = statusBarHeight + 44
///
let iphoneX = ((statusBarHeight != 20) ? true : false)
///
let LOCAL_RELEASE_VERSION = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String
///
let App_Name = Bundle.main.infoDictionary!["CFBundleDisplayName"] as! String
///
let Phone_Model = UIDevice.current.model
///
let System_Version = UIDevice.current.systemVersion
///
let Language_first_local = NSLocale.preferredLanguages.first!
///
var app_Version:String{
if let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String {
return version
}else {
return "1.0.0"
}
}
///
let bottomPadding = UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
///
let placeholderImage:UIImage = UIImage(named: "placeholder")!
///
let privacyUrl:URL = .init(string: "https://musiclax.mystrikingly.com/privacy")!
///
let serviceUrl:URL = .init(string: "https://musiclax.mystrikingly.com/terms")!
//MARK: -
///
typealias ActionBlock = () -> Void?
///A
var MPSideA_ModalType:MPSideA_PresentModal = .Timer
///B
var MPPositive_ModalType:MPPositive_PresentModal = .PlayerList
///
let DocumentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
///
func getDocumentsFileURL(_ videoID: String) -> String? {
// DocumentsURL
let documentsDirectoryURL = DocumentsURL.appendingPathComponent("Downloads")
// videoIdURL
let fileURL = documentsDirectoryURL.appendingPathComponent("\(videoID).mp4")
//
if FileManager.default.fileExists(atPath: fileURL.path) == true {
//
return fileURL.absoluteString
}else {
return nil
}
}
///nextIDID
func improveDataforLycirsAndRelated(_ song:MPPositive_SongItemModel, completion:@escaping(((String?,String?)) -> Void)) {
//next
MP_NetWorkManager.shared.requestNextLyricsAndRelated(song){ result in
completion(result)
}
}
///player
func improveDataforResouceAndCover(_ song:MPPositive_SongItemModel, completion:@escaping((([String],[Int],[String]), [String]?) -> Void)) {
//player
MP_NetWorkManager.shared.requestAndroidPlayer(song.videoId, playlistId: "") { resourceUrls, coverUrls in
completion(resourceUrls,coverUrls)
}
}
///
func setTimesToMinSeconds(_ time:TimeInterval) -> String {
//
let min = Int(time / 60)
let second = Int(time.truncatingRemainder(dividingBy: 60))
return "\(min < 10 ? "0\(min)":"\(min)"):\(second < 10 ? "0\(second)":"\(second)")"
}
///
func setTimesToMins(_ time:TimeInterval) -> String {
//
let min = Int(time / 60)
return "\(min < 10 ? "0\(min)":"\(min)")"
}
///
func authorize(observe:UIViewController) -> Bool{
let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.audio)
switch status {
case .authorized:
return true
case .notDetermined:
//
AVCaptureDevice.requestAccess(for: AVMediaType.audio, completionHandler: {(status) in
DispatchQueue.main.async(execute: {() -> Void in
_ = authorize(observe: observe)
})
})
default: ()
DispatchQueue.main.async(execute: { () -> Void in
let alertController = UIAlertController(title: "Get Microphone Access",message: "“Musiclax” asks you to turn on your microphone to recognize the decibels around you and turns on white noise for you automatically. Please go to the “Settings” page to turn on the microphone permission",preferredStyle: .alert)
let cancelAction = UIAlertAction(title:"Cancel", style: .cancel, handler:nil)
let settingsAction = UIAlertAction(title:"Settings", style: .default, handler: {
(action) -> Void in
let url = URL(string: UIApplication.openSettingsURLString)
if let url = url, UIApplication.shared.canOpenURL(url) {
if #available(iOS 10, *) {
UIApplication.shared.open(url, options: [:],
completionHandler: {
(success) in
})
} else {
UIApplication.shared.openURL(url)
}
}
})
alertController.addAction(cancelAction)
alertController.addAction(settingsAction)
observe.present(alertController, animated: true)
})
}
return false
}
///Label
func createLabel(_ text:String? = nil, font:UIFont, textColor:UIColor, textAlignment:NSTextAlignment, lines:Int = 1) -> UILabel {
let label = UILabel()
label.text = text ?? "text"
label.font = font
label.textColor = textColor
label.textAlignment = textAlignment
label.numberOfLines = lines
return label
}
///
func switchPlayTypeBtnIcon(_ btn:UIButton) {
switch MP_PlayerManager.shared.getPlayType() {
case .normal://
btn.setBackgroundImage(UIImage(named: "List_NormolPlay'logo"), for: .normal)
case .random://
btn.setBackgroundImage(UIImage(named: "Player_Shuffle'logo"), for: .normal)
case .single://
btn.setBackgroundImage(UIImage(named: "Player_Single'logo"), for: .normal)
}
}
///广
func requestTrackingAuthorization(_ observe:UIViewController,max:Int = 0) -> Bool {
if #available(iOS 14, *) {
//
let status = ATTrackingManager.trackingAuthorizationStatus
switch status {
case .notDetermined:
//
print("未知的跟踪状态")
ATTrackingManager.requestTrackingAuthorization { status in
let isAuthorized = status == .authorized
DispatchQueue.main.async {
let new = max + 1
if new < 3 {
_ = requestTrackingAuthorization(observe, max: new)
}
}
}
case .authorized:
// IDFA
print("用户授权跟踪")
return true
case .denied:
print("用户拒绝跟踪")
default:()
print("跟踪状态受限")
}
return false
} else {
return true
}
}
///IDFA
func getIDFA(_ observe:UIViewController) -> UUID? {
if requestTrackingAuthorization(observe) {
let idfa = ASIdentifierManager.shared().advertisingIdentifier
return idfa
}else {
return nil
}
}