Reputation: 979
I am a new coder and am having trouble using the following resource to play a YouTube video in my app
https://github.com/larcus94/LBYouTubeView
I have opened the sample code but in their sample code, it loads the video on app launch but I don't want it to do this at all. I want to load the video in a specific View, perhaps even in a frame but I can't seem to do that
Any direction or help please? I can provide any resources you may need
Upvotes: 0
Views: 650
Reputation: 1644
In your app add a UIView on your nib and set the size of this view to the size you want the video player to be, Then connect it to your code calling the view "viewForYouTube", @Synthisize it in the .m file of your ViewController.
Your .h File should look like that:
#import <UIKit/UIKit.h>
#import "LBYouTube.h"
@interface YourViewController : UIViewController <LBYouTubePlayerControllerDelegate>
@property (weak, nonatomic) IBOutlet UIView *viewForYouTube;
@end
Then add this code to your .m file:
- (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);
}
Upvotes: 1