【问题标题】:Unable to embed YouTube video with YTPlayerView NSCocoaErrorDomain Code=258无法使用 YTPlayerView NSCocoaErrorDomain Code=258 嵌入 YouTube 视频
【发布时间】:2016-03-18 13:46:17
【问题描述】:

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

2015-12-12 20:19:45.229 蜡室 [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

【问题讨论】:

  • 是的也发生在我身上。我手动添加了文件并更改了 youtubeplayer 文件中的文件路径:/。现在找到了更好的解决方案。
  • @MuhammadZohaibEhsan 似乎您只需将版本号设置为 0.1.4 即可,无需任何额外步骤。

标签: ios swift youtube youtube-api ytplayerview


【解决方案1】:

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

到: pod 'youtube-ios-player-helper-swift'

我还必须更改文件上的 import to youtube_ios_player_helper_swift,有些方法的名称略有不同。

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

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        您可以手动将YTPlayerView-iframe-player.html 添加到您的 Xcode 项目(或 Cocoapods 项目/目标)中,或者将 Cocoapods 指向 master 分支,而不是回滚到版本 0.1.4:

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

        【讨论】:

          猜你喜欢
          • 2016-02-11
          • 2012-04-04
          • 2017-08-16
          • 1970-01-01
          • 2017-07-08
          • 2016-04-20
          • 2015-10-29
          • 2016-11-27
          • 2011-09-06
          相关资源
          最近更新 更多