我想在某些内容开始播放时尝试获取视频链接(例如任何YouTube视频).
首先我抓住视频开始播放
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoStarted:) name:@"UIWindowDidBecomeVisibleNotification" object:nil];
Run Code Online (Sandbox Code Playgroud)
然后延迟尝试获取链接
-(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 …Run Code Online (Sandbox Code Playgroud)