I'm trying to get links to a video when something starts playing (like any video on YouTube).
First I will catch when the video starts playing
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoStarted:) name:@"UIWindowDidBecomeVisibleNotification" object:nil];
then with a delay try to get the link
-(void)videoStarted:(NSNotification *)notification { NSLog(@"notification dic = %@", [notification userInfo]); [self performSelector:@selector(detectModal) withObject:nil afterDelay:2.5f]; } -(void)detectModal { CUViewController *controller = (CUViewController *)[appDelegate.window rootViewController].presentedViewController; NSLog(@"Presented modal = %@", [appDelegate.window rootViewController].presentedViewController); if(controller && [controller respondsToSelector:@selector(item)]) { id currentItem = [controller item]; if(currentItem && [currentItem respondsToSelector:@selector(asset)]) { AVURLAsset *asset = (AVURLAsset *)[currentItem asset]; if([asset respondsToSelector:@selector(URL)] && asset.URL) [self newLinkDetected:[[asset URL] absoluteString]]; NSLog(@"asset find = %@", asset); } } else { for (UIWindow *window in [UIApplication sharedApplication].windows) { if ([window.rootViewController.presentedViewController isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) { controller = (CUViewController *)window.rootViewController.presentedViewController; for(int i = 0; i < [controller.view.subviews count]; i++) { UIView *topView = [controller.view.subviews objectAtIndex:i]; NSLog(@"top view = %@", topView); for(int j = 0; j < [topView.subviews count]; j++) { UIView *subView = [topView.subviews objectAtIndex:j]; NSLog(@"sub view = %@", subView); for (int k = 0; k < [subView.subviews count]; k++) { CUPlayerView *subsubView = (CUPlayerView *)[subView.subviews objectAtIndex:k]; NSLog(@"sub sub view = %@ class = %@", subsubView, NSStringFromClass([subsubView class])); if([NSStringFromClass([subsubView class]) isEqualToString:@"AVVideoLayerView"]) { NSLog(@"player view controller = %@", subsubView.playerController); CUPlayerController *pController = subsubView.playerController; NSLog(@"item = %@", [pController player]); CUPlayerController *proxyPlayer = pController.playerControllerProxy; if(proxyPlayer) { AVPlayer *player = [proxyPlayer player]; NSLog(@"find player = %@ chapters = %@", player, proxyPlayer.contentChapters); break; } } } } } } } } }
CUViewController, CUPlayerView, CUPlayerController - fakes it and looks like this
@interface CUPlayerController : UIViewController @property(nonatomic, retain) id playerControllerProxy; @property(nonatomic, retain) id player; @property(nonatomic, retain) id item; - (id)contentChapters; @end
all right up to this line
NSLog(@"find player = %@ chapters = %@", player, proxyPlayer.contentChapters);
Player
always zero. Maybe there is an easier way to get a link to the media?
ios objective-c avplayer
Alexander Yatsenko
source share