gpt4 book ai didi

ios - SWIFT - 无法设置 MPMediaPicker 委托(delegate)

转载 作者:行者123 更新时间:2023-11-28 05:30:37 27 4
gpt4 key购买 nike

代码:

import UIKit
import MediaPlayer

class WelcomeView: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
var mediaPicker: MPMediaPickerController = MPMediaPickerController.self(mediaTypes:MPMediaType.Music)
mediaPicker.allowsPickingMultipleItems = false
mediapicker1 = mediaPicker

}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning() }

var mediapicker1 = MPMediaPickerController()

@IBAction func selectsong(sender: AnyObject) {
self.presentViewController(mediapicker1, animated: true, completion: nil)
}
}

didPickMediaItems 是委托(delegate)方法/如何将委托(delegate)设置为 mediapicker?在网站上,它写得很简单,但我试过了,但它不能 swift 工作。还有,选歌后怎么播放呢?

我用这个网站来创建它: media picker以及来自苹果官方编程指南中关于创建“hello world”音乐应用程序的一些代码)以播放来自 allsongsquery() 的音乐

最佳答案

您需要将 MPMediaPickerControllerDelegate 协议(protocol)添加到您的 UIViewController 类:

class WelcomeView: UIViewController, MPMediaPickerControllerDelegate {

然后您可以将MPMediaPickerController 的委托(delegate)设置为self:

mediaPicker.delegate = self

关于ios - SWIFT - 无法设置 MPMediaPicker 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28719009/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com