【问题标题】:Open YouTube Video in a UIView using LBYouTube使用 LBYouTube 在 UIView 中打开 YouTube 视频
【发布时间】:2014-01-22 10:23:53
【问题描述】:
【问题讨论】:
标签:
ios
iphone
objective-c
xcode
youtube
【解决方案1】:
在您的应用程序中,在您的 nib 上添加一个 UIView 并将此视图的大小设置为您希望视频播放器的大小,然后将其连接到您的代码调用视图“viewForYouTube”,@Synthisize 在 .m你的 ViewController 的文件。
您的 .h 文件应如下所示:
#import <UIKit/UIKit.h>
#import "LBYouTube.h"
@interface YourViewController : UIViewController <LBYouTubePlayerControllerDelegate>
@property (weak, nonatomic) IBOutlet UIView *viewForYouTube;
@end
然后将此代码添加到您的 .m 文件中:
- (void)viewDidAppear:(BOOL)animated
{
// Setup the player controller and add it's view as a subview:
LBYouTubePlayerViewController* controller = [[LBYouTubePlayerViewController alloc] initWithYouTubeURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=1fTIhC1WSew&list=FLEYfH4kbq85W_CiOTuSjf8w&feature=mh_lolz"] quality:LBYouTubeVideoQualityLarge];
controller.delegate = self;
[controller.view setFrame:CGRectMake(0, 0, viewForYouTube.frame.size.width, viewForYouTube.frame.size.height)];
[viewForYouTube addSubview:controller.view];
}
#pragma mark LBYouTubePlayerViewControllerDelegate
-(void)youTubePlayerViewController:(LBYouTubePlayerViewController *)controller didSuccessfullyExtractYouTubeURL:(NSURL *)videoURL {
NSLog(@"Did extract video source:%@", videoURL);
}
-(void)youTubePlayerViewController:(LBYouTubePlayerViewController *)controller failedExtractingYouTubeURLWithError:(NSError *)error {
NSLog(@"Failed loading video due to error:%@", error);
}