Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何解释MPMediaItemCollection代码_Ios_Swift - Fatal编程技术网

Ios 如何解释MPMediaItemCollection代码

Ios 如何解释MPMediaItemCollection代码,ios,swift,Ios,Swift,当我选择在我的应用程序中打印MPMediaItemCollection时,我只会收到诸如0x17eb5d30之类的代码。有人知道如何从这些随机字母和数字中获取数据吗。我希望能在几秒钟内找到歌曲的标题和长度 我的密码在这里 @IBAction func pickSong(sender: AnyObject) { self.presentPicker(sender) func prepareForSegue(segue: UIStoryboardSegue, sender:

当我选择在我的应用程序中打印MPMediaItemCollection时,我只会收到诸如0x17eb5d30之类的代码。有人知道如何从这些随机字母和数字中获取数据吗。我希望能在几秒钟内找到歌曲的标题和长度

我的密码在这里

@IBAction func pickSong(sender: AnyObject) {


    self.presentPicker(sender)


    func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        var DestView: playMusicViewController = segue.destinationViewController as! playMusicViewController
        DestView.selectedSong = MPMediaItemCollection()

    }


}


func presentPicker (sender:AnyObject) {

    let mediaPicker = MPMediaPickerController(mediaTypes: .Music)
    mediaPicker.delegate = self
    mediaPicker.allowsPickingMultipleItems = false
    presentViewController(mediaPicker, animated: true, completion: {})

}
还有扩展视图控制器

extension ViewController : MPMediaPickerControllerDelegate {
// must implement these, as there is no automatic dismissal

    func mediaPicker(mediaPicker: MPMediaPickerController!, didPickMediaItems mediaItemCollection: MPMediaItemCollection!) {
        let player = MPMusicPlayerController.applicationMusicPlayer()
        player.setQueueWithItemCollection(mediaItemCollection)
        player.play()
        println(mediaItemCollection)
        self.dismissViewControllerAnimated(true, completion: nil)

    }

    func mediaPickerDidCancel(mediaPicker: MPMediaPickerController!) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }

}

如果您想访问音乐的详细信息,您需要访问为拾取程序接收回来的对象的属性,那么您看到的数字和字母是指向内存中地址的指针(通常对我们来说不是很有用)。下面的示例显示如何检索所选音乐的标题:

func mediaPicker(mediaPicker: MPMediaPickerController!, didPickMediaItems mediaItemCollection: MPMediaItemCollection!) {
    let player = MPMusicPlayerController.applicationMusicPlayer()
    player.setQueueWithItemCollection(mediaItemCollection)
    player.play()
    let item = mediaItemCollection.representativeItem
    let title = item.title
    println(title)
    self.dismissViewControllerAnimated(true, completion: nil)  
}

我希望这对你有帮助

这个“随机”let和数字是指向内存地址的指针。你需要发布你的代码,这样人们可以在这里帮助你。编辑您的帖子,以显示您正在尝试做什么(代码)和遇到什么(错误消息),我们将很高兴帮助编辑,我没有遇到错误,我只是需要帮助翻译这些字母和数字代表什么。您如何测试它?我在我的iPhone上运行它,它运行得很好这确实运行得很好,我不是在试图修复错误,我是在试图理解我在媒体收藏上使用println时收到的代码。因为我想检索要发送给变量的歌曲标题。像0x17eb5d30这样的代码对我来说基本上是无用的。