I'm creating a youtube videos player which can play a list of youtube video ( given a list of video id). I embedded youtube video into a UIWebview as following:
NSString *htmlFormat = @"<html><head><body style=\"margin:0\"><embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" width=\"40\" height=\"30\"></embed></body></html>";
NSString *url = [NSString stringWithFormat:@"http://www.youtube.com/watch?v=%@", videoId];
NSString *html = [NSString stringWithFormat:htmlFormat, url];
[webView loadHTMLString:html baseURL:nil];
What i need are:
- Next video is played automatically when player finishes playing current one.
- Next video is played when user tap next button in players' control panel
- Stop playing list if user tap 'Done' button.
My approach is handling events that may be sent out when player finish playing, users tap control buttons, so i can modify html content to load other videos.
My question are:
Is there better way to play a list of youtube video given a list of video ids?
How to handle such those events?
I found some solutions that suggest handle notification UIMoviePlayerControllerDidExitFullscreenNotification
and UIMoviePlayerControllerDidEnterFullscreenNotification
, but I can not distinguish between control buttons' events and finish playing event (movie player controller exits fullscreen mode in all the cases). Some suggest using HTML <video>
tag, but i dont think it possible.