Comment recevoir NSNotifications de UIWebView intégré vidéo YouTube de lecture

Je n'ai pas reçu de notifications pour MPMoviePlayerController. Ce que je fais mal?

Je utiliser à la suite de la logique.

Je suis en commençant à lire des vidéos youtube en UIWebView. UIWebView appelle un standard MPMoviePlayerController. Je n'ai pas de contrôle MPMoviePlayerController parce que je n'ai pas instancier MPMoviePlayerController.

Je run youtube du clip avec l'exécution automatique (1 seconde de retard):

[self performSelector:@selector(touchInView:) withObject:b afterDelay:1];

Mon code est:

- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadStateDidChange:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidFinish:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
[self embedYouTube];
}
- (void)loadStateDidChange:(NSNotification*)notification
{
NSLog(@"________loadStateDidChange");
}
- (void)playbackDidFinish:(NSNotification*)notification
{
NSLog(@"________DidExitFullscreenNotification");
}
- (void)embedYouTube
{
CGRect frame = CGRectMake(25, 89, 161, 121);
NSString *urlString = [NSString stringWithString:@"http://www.youtube.com/watch?v=sh29Pm1Rrc0"];
NSString *embedHTML = @"<html><head>\
<body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
videoView.delegate = self;
for (id subview in videoView.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
[videoView loadHTMLString:html baseURL:nil];
[self.view addSubview:videoView];
[videoView release];
}
- (void)webViewDidFinishLoad:(UIWebView *)_webView 
{
UIButton *b = [self findButtonInView:_webView];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(touchInView:) object:b];
[self performSelector:@selector(touchInView:) withObject:b afterDelay:1];
}
- (UIButton *)findButtonInView:(UIView *)view 
{
UIButton *button = nil;
if ([view isMemberOfClass:[UIButton class]]) {
return (UIButton *)view;
}
if (view.subviews && [view.subviews count] > 0) 
{
for (UIView *subview in view.subviews) 
{
button = [self findButtonInView:subview];
if (button) return button;
}
}
return button;
}
- (void)touchInView:(UIButton*)b
{
[b sendActionsForControlEvents:UIControlEventTouchUpInside];
}

Mise à JOUR: je suis en création d'application qui joue de la vidéo de youtube. Vous pouvez exécuter la liste de lecture et vous permettra de voir la première vidéo. Lors de la première vidéo est terminée, la seconde de la vidéo commence à jouer automatiquement et ainsi de suite.

J'ai besoin de soutien ios 4.1 et supérieur.

UPDATE2: @H2CO3 je suis en train d'utiliser votre url, mais il ne fonctionne pas. Délégué de la méthode n'a pas appelé à la sortie de l'événement. J'ai ajouté mon code html url pour vous connecter.
Il est:

<html><head>    <body style="margin:0">    
<script>function endMovie() 
{document.location.href="somefakeurlscheme://video-ended";} 
</script>      <embed id="yt" src="http://www.youtube.com/watch?v=sh29Pm1Rrc0"        
onended="endMovie()" type="application/x-shockwave-flash"  
width="161" height="121"></embed>  
</body></html>
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([[[request URL] absoluteString] hasPrefix:@"somefakeurlscheme://video-ended"]) 
{
[self someMethodSupposedToDetectVideoEndedEvent];
return NO; //prevent really loading the URL
}
return YES; //else load the URL as desired
}

UPDATE3
@Till, je cann pas pris UIMoviePlayerControllerDidExitFullscreennotification, mais j'ai trouvé MPAVControllerItemPlaybackDidEndnotification. MPAVControllerItemPlaybackDidEndnotification s'affiche lorsque la lecture de la vidéo est terminée.

Mais je ne comprends pas comment faire des captures onDone notifications?

  • Votre hypothèse de départ est incorrect. UIWebView ne pas utiliser la norme MPMoviePlayerController pour la lecture.
InformationsquelleAutor Voloda2 | 2011-12-15