【问题标题】:Open YouTube Video in a UIView using LBYouTube使用 LBYouTube 在 UIView 中打开 YouTube 视频
【发布时间】:2014-01-22 10:23:53
【问题描述】:

我是一名新编码员,在我的应用中使用以下资源播放 YouTube 视频时遇到问题

https://github.com/larcus94/LBYouTubeView

我已经打开了示例代码,但在他们的示例代码中,它会在应用启动时加载视频,但我根本不希望它这样做。我想在特定视图中加载视频,甚至可能在一个帧中,但我似乎无法做到这一点

请问有什么方向或帮助吗?我可以提供您可能需要的任何资源

【问题讨论】:

  • 你成功了吗?请分享你的经验。

标签: 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);
}

【讨论】:

    猜你喜欢
    • 2011-02-02
    • 1970-01-01
    • 2019-01-16
    • 2013-03-12
    • 1970-01-01
    • 2020-11-30
    • 2013-02-08
    • 1970-01-01
    • 2016-03-23
    相关资源
    最近更新 更多