13
votes

I am trying to play a YouTube video with the youtube-ios-player-helper library, but I am encountering an error at runtime:

Received error rendering template: Error Domain=NSCocoaErrorDomain Code=258 "The operation couldn't be completed. (Cocoa error 258.)"
4

4 Answers

40
votes

In YTPlayerView.m

Edit:

NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player"
                                                 ofType:@"html"
                                            inDirectory:@"Assets"];

To:

NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player"
                                                 ofType:@"html"];

Hope to help you!

6
votes

You need copy Assets/YTPlayerView-iframe-player.html to main bundle to fix this issue.

or just put into bundle, and replace where App starts to look for

/*NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player"
     ofType:@"html"
     inDirectory:@"Assets"];*/

NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player" ofType:@"html"];
2
votes

Drag and drop

YTPlayerView-iframe-player.html

YTPlayerView.h

YTPlayerView.m

files in your project.

Add bridging header and use this:

#import "YTPlayerView.h"

Go to YTPlayerView.m file :

Find :

NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player"
                                                 ofType:@"html"
                                            inDirectory:@"Assets"];

Change to :

  NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player"
                                                     ofType:@"html"];

In your View Controller:

use :

class ViewController:UIViewController,YTPlayerViewDelegate {

   var playerView = YTPlayerView()

fetch videoID and load :

self.playerView.load(withVideoId: videoID)

self.playerView.playVideo()
}
-1
votes

You didn't give a version of the plugin you have a problem with. In case this is 1.5, there is a bug discussed here: https://github.com/youtube/youtube-ios-player-helper/issues/160.

It is already fixed in master, so, assuming you are using Cocoapods, you may do this:

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