How to open youtube video on UIButton action in iOS? - ios

I want open youtube video on UIButton action and after finishing youtube video. The control come to application by clicking DONE button, How we can achieve this?

1: Create a UIWebView with frame
2: Add it as a SuView
3: loadRequest using URL
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.youtube.com]]];

Related

Youtube embedded videos Done button not working in iOS 10

I am passing an URL link of youtube to a WebView. The video plays in full screen due to which the navigation bar hides, in order to bring the navigation bar back we have to click the "Done" button in the upper left corner. My app works fine with iOS 9 devices but in the latest update i.e iOS 10 this is not working. The done button does not respond or else the screen goes blank and video continues to play. Any help will be highly appreciated.
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#""]];
[webView loadRequest:request];
This is how i pass the URL

How to access built-in media player opened by a UIWebView?

Currently, when a user clicks play button on the video player which is located at a webpage which is opened inside my UIWebView, built-in media player pops-up and covers entire screen.
I'm looking for a way to access that particular movie player instance so I can interact with it.
Is it something doable? If so, how?
I would suggest to create UIButton to run javascript code. For example, below I created a function to control play/pause youtube video.
- (void)clickPlayButton {
NSString *jsCode = [NSString stringWithFormat:#"document.getElementsByClassName('ytp-play-button')[0].click()"];
[myWebView stringByEvaluatingJavaScriptFromString: jsCode];
}

Youtube Playlist in iphone app

I'm wondering wether its possible to play a youtube playlist in an IOS App. i've been struggling to find an answer for this for some time now. i've tried several html5 players, but they do not support youtube playlists. Other than that i've tried using this simple code:
NSURL *url = [NSURL URLWithString:array[selectedRowValue]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
But this will only play the playlist and you wont be able to navigate between the playlist videos.
my question is then is there an API or any kind of sample codes easy to use for this purpose?
i'm thinking about something like this:
You could try implementing a UIWebView into the tableview's header view and have the url change whenever a user selects a specific cell.
You can find the youtube player webview sample in the answer here YouTube Embed player in Iframe doesn't work in iOS6

IPAD : How to play video in fullscreen without User Action

I load html5 / youtube and DMcloud video in a UIWebview on my IPAD with :
[adView loadHTMLString:script baseURL:[NSURL URLWithString:baseURL]];
I want to launch this in fullscreen same with an iphone in fullscreen with controls.
I read more topic. It's may be not possible !
I test with :
edit : adView.mediaPlaybackRequiresUserAction = NO;
mediaPlaybackRequiresUserAction = NO;
but don't works !
I don't want a simple resize but really a full screen.
It's possible without User Action ?
Thanks for your help.
Make sure the property mediaPlaybackRequiresUserAction of webview set to NO.
adView.mediaPlaybackRequiresUserAction = NO;
Check these links for more help How to autoplay a YouTube video in a UIWebView and Youtube video autoplay inside UIWebview

iOS embed video, video still plays when in another view

So lets say I have a UIWebView on my view, embed with a YouTube video. The view is connected to a navigation view controller. This means that when i click a button it pushes a view on to the stack. But when I play the youtube video and go to the next view. The video is still playing. Is there anyway to handle stopping an embed youtube video when going to another view?
What if I have multiple cells with a UIWebView embed with a YouTube video in a UICollectionView? I don't have reference to all the UIWebViews to set to nil. (Sorry for the confusion previously above)
What I do is just set the UIWebView's content to nil when I'm moving to another page, which removes the video player completely, but if you just want to pause the video so the user can resume when they come back, you'll have to talk to the youtube player using javascript. See How to Pause Media Playback in UIWebView for one approach.
If you use Youtube Javascript api to play the video - you can pause it when leaving current view with
-(void)viewWillDisapper:(BOOL)animated
{
[super viewWillDisappear:animated];
[webView stringByEvaluatingJavaScriptFromString: #"player.pauseVideo();"];
}
You need to load a blank page into the UIWebView to stop the video playing. Here's a quick way to do it:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated]
[yourWebView loadHTMLString:nil baseURL:nil];
}

Resources