4

I've embedded the YouTube video with no difficulties following method #2 of the YouTube API Blog:

http://apiblog.youtube.com/2009/02/youtube-apis-iphone-cool-mobile-apps.html

Is there any way to know when the video has finished playing (or when the user presses the Done button on the movie controller)?

For instance, say you wanted to play each video in a playlist without requiring the user to interact with the app. Is there any hook for when to start the next video?

2 Answers2

1

I am afraid you are out of luck. I have searched for the same thing around six months before and came to the conclusion that it is not possible with the current SDK. I have posted a similar question in stack overflow too.

https://stackoverflow.com/questions/4011796/notification-after-video-playback-in-mobile-safari

In general, if you need this kind of functionality, you have to use MPMoviePlayerCOntroller, not a web view.Even then, I don't think youtube URLs are supported by this class.

Community
  • 1
  • 1
Jose Cherian
  • 7,207
  • 3
  • 36
  • 39
  • 2
    I took another stab at this. Although there is no notification that I can find, there is a polling solution that you can use. When the YouTube plugin kicks in, the application's keyWindow is switched. I start a timer and monitor when the UIApplication window is switched back to my AppDelegate's window. delegate.window == [[UIApplication sharedApplication] keyWindow] If they are different, this means the YouTube video is still playing. It's not an ideal solution, but it does the trick. – smoothlandon Mar 03 '11 at 22:32
  • Great trick, but not useful in my case as the window will be closed before receiving the notification. – Jose Cherian Mar 06 '11 at 04:17
  • @smoothlandon: could please post some code! your solution seems to be my last ressort. – Gerold Meisinger Nov 18 '11 at 15:51
0

Going by smoothlandon's post, this is what I implemented to determine if the YouTube/Safari window is still active. My App is really simple and it only has the main window, and a YouTube/Safari view that loads.

viewDidLoad:

activeWindow = [[UIApplication sharedApplication] keyWindow];
windowTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(checkForMedia) userInfo:nil repeats:YES];


- (void) checkForMedia{
  newWindow = [[UIApplication sharedApplication] keyWindow];

  if(newWindow == activeWindow){

  NSLog(@"media is not playing");

  }else{
      NSLog(@"media is playing");
  }
}
Ngoan Nguyen
  • 747
  • 2
  • 9
  • 19