Ashiwani
Ashiwani

Reputation: 131

Error when integrating with youtube-ios-player-helper third party library on iOS

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.)"

Upvotes: 13

Views: 6248

Answers (4)

Hitesh Chauhan
Hitesh Chauhan

Reputation: 1540

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()
}

Upvotes: 2

bartolomeon_n
bartolomeon_n

Reputation: 403

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'

Upvotes: -1

Love Thailand
Love Thailand

Reputation: 767

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!

Upvotes: 40

János
János

Reputation: 35050

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"];

Upvotes: 6

Related Questions