この質問は Stack Overflow 全体にあることは知っていますが、それでも、それらのほとんどは古く、ここで質問する内容とは関係ありません。
だから私は と の配列を持っAVPlayerItems
ていAVQueuePlayer
ます。最初に、配列アイテムを再生するように AVQueuePlayer を設定します。
func mediaPicker(mediaPicker: MPMediaPickerController!, didPickMediaItems mediaItemCollection: MPMediaItemCollection!) {
mediaItems = mediaItemCollection.items
for thisItem in mediaItems as [MPMediaItem] {
var itemUrl = thisItem.valueForProperty(MPMediaItemPropertyAssetURL) as? NSURL
var playerItem = AVPlayerItem(URL: itemUrl)
mediaArray.append(playerItem)
}
updateMetadata()
audioPlayer = AVQueuePlayer(items: mediaArray)
self.dismissViewControllerAnimated(true, completion: nil)
}
しかし、たとえば、ユーザーが新しいアイテムを追加したり、アイテムを削除したりすると、プレーヤーを更新しようとします (最初に設定したのと同じ方法) が、エラーが発生します。回避策、または解決策があるかどうかを知りたいです。これは、ユーザーが曲を削除する方法です。
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == UITableViewCellEditingStyle.Delete{
mediaArray.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
audioPlayer = AVQueuePlayer(items: mediaArray) //here gives the error
}
}
私はこれで自殺しているので、誰かが私を助けてくれれば幸いです.