我是一名新编码员,在使用以下资源在我的应用中播放 YouTube 视频时遇到问题
https://github.com/larcus94/LBYouTubeView
我已经打开了示例代码,但在他们的示例代码中,它在应用程序启动时加载视频,但我根本不希望它这样做。我想在特定 View 中加载视频,甚至可能在框架中加载视频,但我似乎无法做到这一点
请问有什么指示或帮助吗?我可以提供您可能需要的任何资源
最佳答案
在您的应用程序中,在您的 Nib 上添加一个 UIView,并将此 View 的大小设置为您希望视频播放器的大小,然后将其连接到您的代码,调用 View “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);
}
关于ios - 使用 LBYouTube 在 UIView 中打开 YouTube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20925848/