我正在设置一个MPMusicPlayer。现在简单的控制。播放,后退,前进。我有三个IBActions联系起来。对于游戏,它不起作用。我相信我有一次工作。对于setQueue,我尝试了两种方法。一个是给它歌曲()。另一个是做song()。items并将其添加到mediaCollection,然后将其传递给setQueue。都没有工作。
import UIKit
import AVFoundation
import MediaPlayer
class ViewController: UIViewController {
let musicPlayer = MPMusicPlayerController()
let songItems = MPMediaQuery.songs()
//let testItems = MPMediaQuery
func setUp(){
//let mediaCollection = MPMediaItemCollection(items: songItems!)
musicPlayer.setQueue(with: songItems)
musicPlayer.prepareToPlay()
}
@IBOutlet weak var testLabel: UILabel!
@IBAction func skipBack(_ sender: UIButton) {
}
@IBAction func play(_ sender: UIButton) {
if musicPlayer.isPreparedToPlay{
musicPlayer.play()}
testLabel.text = "pressed"
}
@IBAction func skipForward(_ sender: Any) {
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
/*
//Music Access
MPMediaLibrary.requestAuthorization { (status) in
if status == .authorized {
self.setUp()
} else {
print("maybe later g")
}
}
*/
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}//end of class
答案 0 :(得分:0)