我正在尝试使用youtube-ios-player-helper库播放 YouTube 视频,但在运行时遇到错误:
Received error rendering template: Error Domain=NSCocoaErrorDomain Code=258 "The operation couldn't be completed. (Cocoa error 258.)"
我正在尝试使用youtube-ios-player-helper库播放 YouTube 视频,但在运行时遇到错误:
Received error rendering template: Error Domain=NSCocoaErrorDomain Code=258 "The operation couldn't be completed. (Cocoa error 258.)"
在 YTPlayerView.m
编辑:
NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player"
ofType:@"html"
inDirectory:@"Assets"];
至:
NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player"
ofType:@"html"];
希望能帮到你!
您需要将Assets/YTPlayerView-iframe-player.html 复制到主包以解决此问题。
或者只是放入捆绑包中,并替换 App 开始寻找的位置
/*NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player"
ofType:@"html"
inDirectory:@"Assets"];*/
NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player" ofType:@"html"];
拖放
YTPlayerView-iframe-player.html
YTPlayerView.h
YTPlayerView.m
项目中的文件。
添加桥接头并使用它:
#import "YTPlayerView.h"
转到 YTPlayerView.m 文件:
寻找 :
NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player"
ofType:@"html"
inDirectory:@"Assets"];
改成 :
NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player"
ofType:@"html"];
在您的视图控制器中:
利用 :
class ViewController:UIViewController,YTPlayerViewDelegate {
var playerView = YTPlayerView()
获取 videoID 并加载:
self.playerView.load(withVideoId: videoID)
self.playerView.playVideo()
}
您没有提供有问题的插件版本。如果这是 1.5,这里讨论了一个错误:https ://github.com/youtube/youtube-ios-player-helper/issues/160 。
它已经在 master 中修复了,所以,假设你使用的是 Cocoapods,你可以这样做:
pod 'youtube-ios-player-helper', :git=>'https://github.com/youtube/youtube-ios-player-helper', :commit=>'head'