【问题标题】:Setting up programmatically the Youtube YTPlayer for iOS以编程方式设置适用于 iOS 的 Youtube YTPlayer
【发布时间】:2014-10-08 17:48:12
【问题描述】:

我在以编程方式从 Youtube API 设置 YTPlayer 时遇到问题,而不是像他们在 example.. 中显示的那样在 Storyboard 上设置 YTPlayer。

这是我试图做的,但不是运气,视频不会加载..

这是我的 viewDidLoad 我尝试设置所有内容的地方。另外,我几乎忘了说我下载了他们的主 framework 并添加到我的项目中。我也更改了 .html 文件的路径。我已经尝试过他们展示的 Storyboard 和作品,但我真的希望能够以编程方式完成。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.myView = [[YTPlayerView alloc] initWithFrame:CGRectMake(10, 80, 300, 275)];
    self.myView.backgroundColor = [UIColor lightGrayColor];

    [self.view addSubview:self.myView];

    [self.myYoutubePlayer loadWithVideoId:@"Yf5_ZQcP7y0"];

    self.playBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 400, 120, 80)];
    [self.playBtn setTitle:@"Play" forState:UIControlStateNormal];
    self.playBtn.backgroundColor = [UIColor redColor];
    [self.playBtn addTarget:self action:@selector(playVideo:) forControlEvents:UIControlEventTouchDown];

    self.stopBtn = [[UIButton alloc] initWithFrame:CGRectMake(190, 400, 120, 80)];
    [self.stopBtn setTitle:@"Stop" forState:UIControlStateNormal];
    self.stopBtn.backgroundColor = [UIColor redColor];
    [self.stopBtn addTarget:self action:@selector(stopVideo:) forControlEvents:UIControlEventTouchDown];

    [self.view addSubview:self.playBtn];
    [self.view addSubview:self.stopBtn];

}

还有播放和停止方法...

- (IBAction)playVideo:(id)sender {
    [self.myYoutubePlayer playVideo];
}

- (IBAction)stopVideo:(id)sender {
    [self.myYoutubePlayer stopVideo];
}

如果需要更多信息,请先询问,我很乐意提供.. :) 谢谢!

【问题讨论】:

  • 嗨,我在 iOS 8.1 上运行这些代码时遇到问题:github.com/youtube/youtube-ios-player-helper/issues/40。你面对吗?我只是警告,但我担心 Apple 会拒绝我的应用。
  • 我没有遇到任何这些问题。你可以检查我的 youtube 播放器并使用它。让我知道它是怎么回事。去here..
  • 谢谢,但错误仅在自动全屏模式下显示或在没有 playerVars 的情况下加载播放器,我通过设置播放器尺寸和屏幕尺寸来修复它!
  • 我认为是与this... 一起检查播放器框架中是否有它。但是,我的意思是我在使用我自己的框架时没有遇到任何这些错误全屏或内联..

标签: ios objective-c ios7 youtube youtube-api


【解决方案1】:

我在这里遇到的问题是YTPlayerView 框架没有正确定义要加载和用于播放器的 iframe.html 文件。所以,我修复了在函数-loadWithPlayerParams: 中更改TYPlayerView.m 并更改此文件路径的任何内容..

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

这将使工作完成..! :)

【讨论】:

    【解决方案2】:

    我认为你的代码有错误。

    您在“self.myYoutubePlayer”上调用“loadWithVideoId”,它应该在“self.myView”上

    【讨论】:

      猜你喜欢
      • 2016-07-02
      • 2012-05-26
      • 2012-06-07
      • 2011-10-13
      • 2013-02-19
      • 2011-12-09
      • 2015-05-15
      • 2017-08-21
      • 2011-02-27
      相关资源
      最近更新 更多