简体   繁体   English

SWIFT-无法设置MPMediaPicker委托

[英]SWIFT - Can't set MPMediaPicker delegate

Code: 码:

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)
}
}

the didPickMediaItems is delegate method/ how can i set the delegate to mediapicker? didPickMediaItems是委托方法/如何将委托设置为mediapicker? on the web site it writen simply but i tryed it and it doesnt work in swift. 在网站上,它写得很简单,但是我尝试了一下,但并没有迅速起作用。 and also, after pick the song how to play it? 而且,选好歌曲后如何播放呢?

i used this websites to create it: media picker and some code from official apple Programming Guide about creating the "hello world" music app) to play music from allsongsquery() 我用这个网站来创建它: 媒体选择器和来自苹果官方编程指南中有关创建“ hello world”音乐应用程序的一些代码,以播放allsongsquery()的音乐

You need to add the MPMediaPickerControllerDelegate protocol to your UIViewController class: 您需要将MPMediaPickerControllerDelegate协议添加到UIViewController类中:

class WelcomeView: UIViewController, MPMediaPickerControllerDelegate {

Then you can set the delegate of your MPMediaPickerController to self : 然后,您可以将MPMediaPickerController的委托设置为self

mediaPicker.delegate = self

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM