【问题标题】:Playing video with youtube-ios-player-helper使用 youtube-ios-player-helper 播放视频
【发布时间】:2016-04-26 12:53:41
【问题描述】:

我一直在尝试从 YouTube 获取我的应用流视频,从 AppCoda 教程中学习,到目前为止,我已经成功连接到它的 JSON 数据库,并从我需要的视频中下载了信息。但是,当我将它提供给 YouTube 播放器库时,它给了我一个错误:

Error Domain=NSCocoaErrorDomain Code=258 "The file name is invalid."

我检查了 AppCoda 示例,似乎我的应用程序的工作方式非常相似。我什至在调用函数之前打印了 videoID 以确保它是正确的。

func getVideos(pID: String, completion: (result:String)->()) {

        Alamofire.request(.GET, videosURL).validate().responseJSON { response in
            switch response.result {
            case .Success:
                if let value = response.result.value {
                    let json = JSON(value)
                    var videoID: [String] = []
                    for var i=0; i<json["items"].count; i++ {
                        let newID = json["items"][i]["snippet"]["resourceId"]["videoId"].stringValue
                        videoID.append(newID)
                        defaults.setObject(videoID, forKey: "\(pID)videoID")
                    }
                    completion(result: "done")
                }
            case .Failure(let error):
                print(error)
                completion(result: "done")
            }
        }
    }

        print(videoID) //Returns: 7zAxweqsSfo
        playerView.loadWithVideoId(videoID)
}

【问题讨论】:

    标签: ios swift youtube youtube-api ytplayerview


    【解决方案1】:

    最新版本的 YouTube iOS Helper Library 不包含播放器所需的 YTPlayerView-iframe-player.html 文件。相关讨论见this GitHub issue

    解决方法是手动将YTPlayerView-iframe-player.html添加到你的项目中,或者将Cocoapods指向master分支:

    pod 'youtube-ios-player-helper', :git=>'https://github.com/youtube/youtube-ios-player-helper', :commit=>'head'
    

    【讨论】:

    • 完美运行!感谢您的帮助!
    猜你喜欢
    • 2014-12-02
    • 2017-01-31
    • 2015-12-16
    • 2018-01-07
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    • 2016-03-23
    • 2015-12-04
    相关资源
    最近更新 更多