我有问题设置YTPlayer从Youtube API编程,而不是在故事板,因为他们在他们的例子中显示。
这就是我试图做的,但运气不好,视频不会事件加载..
这是我的viewDidLoad,我试图设置一切…另外,我差点忘了说我下载了他们的主框架并添加到我的项目中。我还更改了.html文件的路径。我已经尝试过了,正如他们用Storyboard和works展示的那样,但我真的希望能够通过编程来实现。
- (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];
}
如果需要更多的信息,请先问,我很乐意提供。:)谢谢!
我在这里遇到的问题是YTPlayerView
框架没有正确定义要加载和用于播放器的iframe.html文件。所以,我在-loadWithPlayerParams:
函数中修改了TYPlayerView.m
,并改变了这个文件的路径。
NSError *error = nil;
NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player"
ofType:@"html"
inDirectory:@""];
这将使工作完成…!:)
我想你的代码有错误。
你在"self"上调用"loadWithVideoId"。myYoutubePlayer",它应该在"self。myview "