7

嵌入 YouTube 视频YTPlayerView不起作用。它只会在日志中给我这个错误:

2015-12-12 20:19:45.229 Wax-room[8545:3426005] 收到错误渲染模板:Error Domain=NSCocoaErrorDomain Code=258 “文件名无效。”

所以我用谷歌搜索了它,它显然与“YTPlayerView-iframe-player.html”丢失有关。我已经尝试了所有建议的位置,但要么是错误的,要么是我做错了。文档在将它与 Swift (2.x)、Cocoapods 和 iOS 9 一起使用时非常糟糕。

https://developers.google.com/youtube/v3/guides/ios_youtube_helper

pod 中也没有 Assets 文件夹。

只是偶然发现了这个:

问题是 YTPlayerView-iframe-player.html 文件不再被复制。我恢复到 0.1.4,现在我看到了 html 页面,它又可以工作了 https://github.com/youtube/youtube-ios-player-helper/issues/160

它是最新版本 0.1.5 中的一个错误。更改为 0.1.4,现在可以使用。检查这个: https ://github.com/youtube/youtube-ios-player-helper/issues/157

4

4 回答 4

3

Podfile 的更改对我没有帮助。

最后我让它在这些步骤中工作。

  1. 从 Podfile 中删除 youtube-ios-player-helper
  2. 运行“pod 更新”
  3. 现在您已经清理了 youtube-ios-player-helper 的 pod。现在将 YTPlayerView.m、YTPlayerView.h 拖到项目中并选择“如果需要复制文件”。将 YTPlayerView-iframe-player.html 复制到项目文件夹并将其添加到“支持文件”组中。
  4. 在 YTPlayerView.m 中从这里改变:

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

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

我已经在我的手机上对此进行了测试,并且效果很好。

于 2016-08-02T17:55:38.583 回答
3

与其回滚到版本 0.1.4,不如手动添加YTPlayerView-iframe-player.html到 Xcode 项目(或 Cocoapods 项目/目标),或将 Cocoapods 指向主分支:

pod 'youtube-ios-player-helper', :git=>'https://github.com/youtube/youtube-ios-player-helper', :commit=>'head'
于 2016-01-20T15:39:15.007 回答
1

将“youtube-ios-player-helper”文件夹中包含的“Assets.bundle”(从 Git 解压缩项目文件夹后)添加到您的 xcode 项目中。这为我解决了这个问题。

于 2016-07-27T14:18:44.507 回答
0

我将 Podfile 中的 pod 名称更改为: pod 'youtube-ios-player-helper' (这是官方文档告诉你要做的)

收件人:pod 'youtube-ios-player-helper-swift'

我还必须在我的文件中将导入更改为 youtube_ios_player_helper_swift,并且某些方法的名称略有不同。

我尝试了上面的大多数答案都无济于事。我只会得到一个白色的矩形来查看。希望这对你有用。

(截至 2021 年 11 月,pod 'youtube-ios-player-helper-swift' 的 pod 版本 1.1)

于 2021-11-09T20:54:13.303 回答