Music_Player3/MusicPlayer/MP/Common/Macro(宏定义与全局量)/Macro.swift
2024-05-14 15:04:59 +08:00

130 lines
5.2 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
@_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!
///
let Location_First = MP_LocationManager.shared.requestLocation()
///
let bottomPadding = UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
///
let placeholderImage:UIImage = UIImage(named: "Home First'placeholder")!
///
let privacyUrl:URL = .init(string: "https://musicoo.app/privacy")!
///
let serviceUrl:URL = .init(string: "https://musicoo.app/terms")!
//MARK: -
///
typealias ActionBlock = () -> Void?
///A
var MPSideA_ModalType:MPSideA_PresentModal = .Timer
///B
var MPPositive_ModalType:MPPositive_PresentModal = .PlayerList
///
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: "“Musicoo” 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)
}
}