【发布时间】: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