1

在函数中如何初始化 MPMusicPlayerMediaItemQueueDescriptor,作为 Music Kit 的 prepend 方法部分的第一步?我想我需要我的媒体查询成为一个队列描述符,并相信我需要初始化它,但不知道怎么做!

该类的 Apple 文档(https://developer.apple.com/documentation/mediaplayer/mpmusicplayermediaitemqueuedescriptor)建议我的函数应该是这样的:

    func playPlaylistNext(chosenPlaylist: String?) {
                var QueueDescriptor: MPMusicPlayerMediaItemQueueDescriptor
                let myMediaQuery = MPMediaQuery.songs()
                let predicateFilter = MPMediaPropertyPredicate(value: chosenPlaylist, forProperty: MPMediaPlaylistPropertyName)
                myMediaQuery.filterPredicates = NSSet(object: predicateFilter) as? Set<MPMediaPredicate>
                init(query: myMediaQuery) {
                        // What needs to go in here
                }
                    musicPlayerController.prepend(QueueDescriptor)
                }
            }
4

1 回答 1

0

回答:

            let myMediaQuery = MPMediaQuery.songs()
            let predicateFilter = MPMediaPropertyPredicate(value: chosenPlaylist, forProperty: MPMediaPlaylistPropertyName)
            myMediaQuery.filterPredicates = NSSet(object: predicateFilter) as? Set<MPMediaPredicate>
            let qd: MPMusicPlayerMediaItemQueueDescriptor = .init(query: myMediaQuery)
            musicPlayerController.prepend(qd)
于 2019-12-13T15:42:37.000 回答