How to play YouTube video in vertical mode? - ios

YouTube player update allow vertical video can display fullscreen in vertical mode. I was asked to fit YouTube video in a vertical view (not a full screen mode) in our iOS app.
We use YTPlayerView to playing YouTube video, but it doesn't provide any method to check if a video is vertical. I guess we can query such the info from YouTube web API, but I couldn't find any thing.
Has anyone tried to do the same thing like mine?

If it's not fullscreen mode then:
NSDictionary *playerVars = #{
#"playsinline" : #1,
};
[self.playerView loadWithVideoId:#"VIDEO_ID" playerVars:playerVars];
Just adjust the view's position etc, it will play just fine. Edit the html file they provide so the background matches your app's etc if you don't like the black.

Related

youtube-ios-player-helper not showing iOS like video player controls

I am using https://github.com/youtube/youtube-ios-player-helper to play videos from youtube in my app.
I am also using different playvars to control what to and what not to show on the player. But the controls section I see on the player is not like iOS.
I tried in other sample app where I could get the proper controls.
NSDictionary *playerVars = #{
#"playsinline" : #1,
#"showinfo":#0,
#"autohide":#1,
#"modestbranding":#1
};
[self.playerView loadWithVideoId:self.videoId playerVars:playerVars];
I played with few other options with these vars but no luck. I am not sure what controls what type of controls are displayed from apps perspective.
Tracked down the issue. It was the custom user agent I was setting for my app, which was causing youtube player to behave differently.

Youtube video in a UIWebView with small frame

In my app I'm supposed to make a menu where users can play a video from a list. The list is presented in a horizontal UIScrollView and I have a frame of 120x80 (in points, in pixels it's 240:160 on retina). The links for videos are either youtube urls or addresses of .m3u8 files on our server (I put them in a simple html from apple's http live streaming documentation).
My problem is with the youtube urls. These pages opened in UIWebView always have a bar on top that limits the tappable surface to half. Also when I play the video for first time another bar shows up (for like, dislike and things like that), which limits the space that will launch the video on tap to 0.
My goal here is to have the videos represented by images (UIImageViews) with buttons on top of them in shape of the "Play" triangle. When I press that UIButton, the video should show, as normal, inside an MPMovieController.
So I need 1 of 2 things:
Have the UIWebView show just the video of the youtube page, without the bars.
Make the youtube video show inside an MPMovieController after user taps a UIButton.
Any tips on how to do either of these?
Yes you can do like this and you need use set property on UIWebView.look this example
here

Play Youtube video in a UIWebView without full screen

I would like to emebed a Youtube video in my app. But normal technique is, we embed a youtube video in a UIWebView and when user clicks, it automatically launches in a MPMoviePlayerController. But this launches in full screen. How to play this youtube video in a MPMoviePlayerController without going to full screen. I would like to display this in a half of the screen.
There are several ways to do that. In addition to setting:
videoView.allowsInlineMediaPlayback = YES;
The easiest and dirtiest way is to disable controls like this:
Method 1
Notice controls: 0
const player = new YT.Player("player", {
width: "100%",
height: "50%",
videoId: "[your video id]",
playerVars: {
controls: 0,
rel: 0,
modestbranding: 1,
html5: 1,
showinfo: 0,
},
});
Method 2
HTML Embedded iFrame code (notice the &controls=0 and/or &playsinline=1)
<iframe
id="ytplayer"
type="text/html"
width="100%"
src="http://www.youtube.com/[your_video_id]?autoplay=1&controls=0&playsinline=1&modestbranding=1&rel=0&showinfo=0&autohide=1&html5=1"
webkit-playsinline
frameborder="0"
></iframe>;
You only add &playsinline=1 (or playsinline:1 in the Javascript case next inside the playerVars)
In this case, user will still be able to go full screen, but the player should start normally in the borders of your view.
I hope this helps.
I'm using a UIView which is defined as a YTPlayerView to play the video.
I followed this tutorial: YouTube Tutorial to Embed Video
I created a dictionary. I then added it to the videoId definition (which video I'm playing).
From YouTube Tutorial:
Replace the loadWithVideoId: call with this code:
OBJECTIVE-C
NSDictionary *playerVars = #{
#"playsinline" : #YES,
};
[self.playerView loadWithVideoId:#"M7lc1UVf-VE" playerVars:playerVars];
Swift 2.1:
var playerVars = ["playsinline" : 1]
videoId.loadWithVideoId(["videoId"], playerVars: playerVars)
This will disable the full screen when trying to play the video, and it will also allow the user to go full screen if they want.
Hope that helps someone.
you set allowsinlinemediaplayback. but this feature on iPad. in iPhone not applicable. If you try play video with uiwebview on iPhone it will be played in full screen mode.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html
Wrap the video in html5 file and add webkit-playsinline in the attribute of <video> tag. Then set webView.allowsInlineMediaPlayback = YES; That works perfect for me.
There still doesn't seem to be a way to do this with MPMoviePlayerController, but the best workaround that uses a UIWebView is the YTPlayer open sourced by Youtube. You can get the source on Github, then you can just follow this tutorial.
I simply followed that tutorial and it works pretty well and is fairly customizable. Full screen plays in an AVFullScreenViewController which is a system standard, thus, it can be rotated for even better full screen viewing.

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.

iPhone: How to play a YouTube video in a certain view (instead of fullscreen)

I found a lots posts about playing mp4 in MPMoviePlayerController (can be in a smaller view in screen) or play youtube video in YTMoviePlayer (fullscreen). I'd like to know if there are someways to play a YouTube video in a certain view? Like apple's example code for MPMoviePlayerController?
https://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html
Thanks you
You should try this. LBYoutubeView. This allows you to play a video in specific view frame.
If you're using an iPhone, there's no way of using the MPMoviePlayerController other than fullscreen. With the iPad, it's a different story, you can embed the player in another view.

Resources