【发布时间】:2015-07-11 12:05:05
【问题描述】:
我正在尝试在某些内容开始播放时获取视频链接(例如任何 YouTube 视频)。
首先我捕捉到视频开始播放的时间
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoStarted:) name:@"UIWindowDidBecomeVisibleNotification" object:nil];
然后延迟尝试获取链接
-(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 - 假的类,看起来像这样
@interface CUPlayerController : UIViewController
@property(nonatomic, retain) id playerControllerProxy;
@property(nonatomic, retain) id player;
@property(nonatomic, retain) id item;
- (id)contentChapters;
@end
在这一行之前一切都很好
NSLog(@"find player = %@ chapters = %@", player, proxyPlayer.contentChapters);
玩家总是零。也许有更简单的方法来获取媒体链接?
【问题讨论】:
-
您想获取正在浏览器中播放的视频的 URL 还是我误会了您?
-
是的,从 uiwebview 开始播放
-
如果你以后想下载视频,我得告诉你,Apple 会拒绝你的申请。 Mercury Browser 做了同样的事情,不得不删除这个功能。
-
我知道如何通过它。
-
几年前我在 iOS 4 上做过同样的事情。我会看看它。
标签: ios objective-c avplayer