在Swift 4中初始化Array中的AVPlayerItem时NSURLErrorCancelled

时间:2018-03-16 17:16:58

标签: ios swift swift4 avplayeritem

我正在尝试在这样的数组中初始化AVPlayerItem:

func parsePlaylist(json: JSON) {
    var i : Int = 0
    while i < json.count {
        let itemId = json[i]["itemid"].intValue
        let position = json[i]["position"].intValue
        let author = json[i]["author"].stringValue
        let title = json[i]["title"].stringValue
        let url = json[i]["url"].stringValue

        let playerItem = AVPlayerItem(url : json[i]["url"].url!)
        //ERROR - Task <89776295-F9F3-4BBC-8908-5F0201A4CDBB>.<2> finished with error - code: -999

        playlistItem.append(PlaylistItem(myItemId: itemId, myPosition: position, myAuthor: author, myTitle: title, myUrl: url, myPlayerItem: playerItem))
        i += 1
    }
}

执行此操作时,控制台显示json.count-乘以上述错误。

稍后尝试初始化我的播放器时:

var player : AVPlayer?
player = AVPlayer(playerItem: playlistItem[itemCounter].playerItem)

一切正常。

如何摆脱错误? 谢谢!

0 个答案:

没有答案