I have been trying to have my app stream videos from YouTube, learning from the AppCoda tutorial and so far I have successfully connected to its JSON database, and downloaded the info from the video I need. However, when I feed it to the YouTube player library, it gives me an error:
Error Domain=NSCocoaErrorDomain Code=258 "The file name is invalid."
I checked against the AppCoda example and it seems that my app is working very similarly. I am even printing the videoID before calling the function to make sure that it is correct.
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)
}
The latest version of the YouTube iOS Helper Library does not include the YTPlayerView-iframe-player.html
file needed by the player. See this GitHub issue for related discussion.
The solution is to manually add the YTPlayerView-iframe-player.html
to your project, or point Cocoapods at the master branch:
pod 'youtube-ios-player-helper', :git=>'https://github.com/youtube/youtube-ios-player-helper', :commit=>'head'