我有问题从Youtube API设置YTPlayer的编程,而不是通过故事板,他们显示在他们的示例。
这就是我想做的,但不是运气,这段视频不会加载事件。
这是我的viewDidLoad,我试着把一切都安排好.而且,我几乎忘了说我下载了他们的主框架并添加到我的项目中。我也更改了.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];
}如果需要更多的信息,请先问,我很乐意提供。))谢谢!
发布于 2015-01-16 18:33:23
我在这里遇到的问题是,YTPlayerView框架没有正确定义要加载和使用的iframe.html文件。因此,我修正了在函数TYPlayerView.m中更改-loadWithPlayerParams:并更改该文件路径的所有内容。
NSError *error = nil;
NSString *path = [[NSBundle mainBundle] pathForResource:@"YTPlayerView-iframe-player"
ofType:@"html"
inDirectory:@""];这将使工作完成.)
发布于 2014-08-17 16:48:18
我认为你的代码有错误。
你在"self.myYoutubePlayer“上叫”self.myYoutubePlayer“,在"self.myView”上叫“self.myView”
https://stackoverflow.com/questions/25318840
复制相似问题