I am creating one application, in that i need to play youtube videos in a native player and also download youtube videos into application. please help me in this
Asked
Active
Viewed 1,587 times
2 Answers
0
To grab the url / download the video help should be available here: Save Youtube video to iPhone in the app.
If you have the direct video url you could stream it with the native MPMoviePlayerController.
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:youTubeDirectURL];
[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
[mp setFullscreen:YES];
[self.view addSubview:mp.view];
[mp prepareToPlay];
[mp play];
0
NSString *youTubeVideoHTML = @"<html><head><style>body{margin:0;}</style></head> <body> <div id=\"player\"></div> <script> var tag = document.createElement('script'); tag.src = 'http://www.youtube.com/player_api'; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { width:\'100%%\', height:'339px', videoId:\'%@\', events: { 'onReady': onPlayerReady } }); } function onPlayerReady(event) { event.target.playVideo(); } </script> </body> </html>";
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, videoId];
videoView = [[UIWebView alloc] initWithFrame:CGRectMake(12.0f, 247.0f, 743.0f, 339.0f)];
videoView.backgroundColor = [UIColor clearColor];
videoView.opaque = NO;
videoView.scrollView.scrollEnabled=NO;
// videoView.delegate = self;
[self.view addSubview:videoView];
videoView.mediaPlaybackRequiresUserAction = NO;
[videoView loadHTMLString:html baseURL:[[NSBundle mainBundle] resourceURL]];

Bryan Roberts
- 3,449
- 1
- 18
- 22

maddy
- 41
- 6