ios - 使用 LBYouTube 在 UIView 中打开 YouTube 视频

标签 ios iphone objective-c xcode youtube

我是一名新编码员,在使用以下资源在我的应用中播放 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/

相关文章:

ios - 如何使用 UIBezierPath 更改元素的颜色?

ios - Apple 远程推送通知在沙盒和生产模式下的行为似乎有所不同

objective-c - 对象在 presentModalViewController 之后返回 null

ios - Objective-C/CocoaHTTPServer - 是否可以在没有任何 UI 的情况下将 CocoaHTTPServer 作为后台应用程序运行?

iPhone/iPad 上下文菜单

ios - 向 NavigationItem 添加按钮

iphone - 在 UITableView 中显示元素,就像 iPhone 联系人一样,分成按字母顺序排列的部分?

objective-c - NSDataDetector - 仅解析时间时移动时区(无 mm/dd/yyyy)

ios - 根据当前位置和方向获取可见的坐标

iphone - iOS CXMLElement 字符串值