IPAD : How to play video in fullscreen without User Action - ios

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

Related

How to play Youtube Video from a browser app on non full screen in Objective C

I am working on Browser app, I want when user searches any video on youtube.com the video is playing on full screen but I want the video to be open on a fixed size small frame, Say Half of phone screen size.
I have Video url and video id. I have integrated YOUTube API but as soon as I hit play button on youtube player it plays on full screen.
Please find codebase of integration
self.playerView = [[YTPlayerView alloc]init];
self.playerView.frame = webView.frame;
[self.playerView loadWithVideoId:str];
[webView.superview addSubview:self.playerView];
Please find the screenshots
When youtube player is added and After tap on play button
Help will be much appreciated.
Does you project have Controller named MainViewController , that controller should have issue with YTPlayerView, please check for this view in your view controller.
in most of the cases it will not defined in the class you have directly use in the code
Searching for the issue in your code i found a property of UIWebview which will help you in playing video inline setAllowsInlineMediaPlayback
With help of this you can directly play the youtube video in the webview,
Here is code sample which you can use to play youtube video
NSString *strVideoId = #"M7lc1UVf-VE";
NSString *videoURL = [NSString stringWithFormat:#"https://www.youtube.com/embed/%#?feature=player_detailpage&playsinline=1",strVideoId];
NSString* embedHTML = [NSString stringWithFormat:#"\
<html><head>\
<style type=\"text/css\">\
iframe {position:absolute; top:50%%; margin-top:-130px;}\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<iframe width=\"100%%\" height=\"240px\" src=\"%#\" frameborder=\"0\"></iframe>\
</body></html>",videoURL];
[self.mainwebview setAllowsInlineMediaPlayback:true];
[self.view addSubview:self.mainwebview];
[self.mainwebview loadHTMLString:embedHTML baseURL:nil];
In this code you can pass any video id which you were passing in the loadWithVideoId of YTPlayerView
To change the width/height you can make change in the width=\"100%%\" height=\"240px\" portion of the iframe
It is working for me in the iPhone also which is looking like this:
iframe youtube play in iPhone
Another reference the setAllowsInlineMediaPlayback working in iPhone: https://stackoverflow.com/a/15189889/4557505
The image which you shown in the screenshot looks like particular video issue
Note This code does not require YTPlayerView so if this code works for you, you can remove the YTPlayerView from your project if this is not used anywhere else
Update Some video not playing:
I think this issue has not nothing to do with the specific implementation as for me it's not working in browser(with embed Url which we are setting in iFrame) or YTPlayerview also
But till than i check and may be find some issue in implementation and as you have mentioned:
Yes all videos worked on YTPlayerView. These videos work on normal
full screen mode but not with embedded player
If you want to make implementation in the YTPlayerview you can check the following code:
NSString *strVideoId = #"3bMYgo_S0Kc";
self.playerView = [[YTPlayerView alloc]init];
self.playerView.frame = CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height/2);
[self.playerView loadWithVideoId:strVideoId playerVars:#{#"playsinline":#1}];
[_mainwebview addSubview:self.playerView];
[self.mainwebview setAllowsInlineMediaPlayback:true];
[self.view addSubview:self.mainwebview];
In the loadWithVideoId we can provide the inline parameter which can solve the problem of full screen and this may work for you on the iPhone also
Note this video is not working on YTPlayer or in browser(embedded url) for me but based on your comment you can try this
#Pyro
setAllowsInlineMediaPlayback works only for ipad, I have already enabled it. and it does now worked, It is not allowing to play the video.
Image after implementation

iOS does not show/play video in UIWebView iframe

I use UIWebView with the:
var html:String = "<iframe src='http://46.101.234.111/trailers/suicide_squads_1' width='100%' height='200px' scrolling='no' frameborder='no'></iframe>"
cell.trailerView.loadHTMLString(html, baseURL: nil)
but it doesn't show/play the video on start. It just show play icon on white row and when I press on it - nothing happens.
iframe works, I checked it. What is the problem and how can I fix it?
Videos on the iPhone will not auto play from websites. Also make sure the video is in a format that can be played on an iPhone.

Direct full screen of html5 video when starting to play in UIWebview

We serve 3rd party videos in a iOS native app through UIWebviews.
On the iPhone when playing a video it directly switches to a fullscreen video view. On the iPad the video plays inline. This is expected according to Apple documentation.
This is because the value:
webView.allowsInlineMediaPlayback
is by default set to NO on iPhone and YES to iPad.
I would like to see the same behaviour on playback on the iPhone as on the iPad. So that is plays the video directly fullscreen. Setting webView.allowsInlineMediaPlayback to NO does not do the trick.
In your HTML5 source code add playsinline like in this example:
video controls="controls" webkit-playsinline="webkit-playsinline">
In your app, in the method you are calling to setup webview add
webView.allowsInlineMediaPlayback = YES;
Unfortunately the conclusion here is that it is not possible.

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];
}

How can I force a video played in a UIWebView to be full screen on an iPad?

I'm playing a YouTube video using a UIWebView, like so:
self.webView.mediaPlaybackRequiresUserAction = NO;
self.webView.allowsInlineMediaPlayback = NO;
[self.webView loadHTMLString:videoEmbedCode baseURL:nil];
I want to force the video to play in full screen without the user tapping the button at the bottom right. This works fine on an iPhone (tap the player to play and it automatically enters full screen), but doesn't work on an iPad (the normal inline player is shown).
I assumed that setting allowsInlineMediaPlayback to NO would do the trick, but apparently not.
Is there a way to force HTML5 videos to play in full screen on an iPad?
If you are trying to play a youtube video in fullscreen directly, then Use a webview of size fullScreen and then handle its rotation accordingly and change the player size of Rotation too. If you need more help then i can help you with the code too for how to change the player size on rotation too.

Resources