youtube-ios-player-helper
youtube-ios-player-helper copied to clipboard
YouTube always expands to full screen when starts playing
Xcode: 9.1 (9B55)
iOS: 11.1
YouTube iOS Player: pod "youtube-ios-player-helper", "~> 0.1.6"
Repro steps
- Create a new Swift project in Xcode
- Add an Objective-C bridging header, and
#include "YTPlayerView.h"
there - Add a view to the main view controller (
Main.storyboard
) and change the view's class toYTPlayerView
; add appropriate constrains (e.g., left, top, right and height/width proportion) - Connect the view to
playerView
field inViewController.swift
- Add
playerView.load(withVideoId: "M7lc1UVf-VE")
to the end ofviewDidLoad()
method inViewController.swift
- Run the app in a simulator
- Wait till the video is loaded
- Press Play button in the YouTube player
Expected result
The video starts playing in the inline mode (the YouTube player doesn't change its size / bounds).
Actual result
The player goes to the full-screen mode. If you switch it back to the inline mode from the full-screen one, the video stops. You press Play again, the video expands at full screen again. There is no way to play a video not having the YouTube played expanded to the full screen.
This fixed the issue for me, it controls the embedded webView and play it inline.
youtubePlayer.load(withVideoId: videoID, playerVars: ["playInline" : 1])
Hope this helps : )
Swift:
let playvarsDic = ["controls": 1, "playsinline": 1, "autohide": 1, "showinfo": 1, "autoplay": 1, "modestbranding": 1]
YoutubePlayer.load(withVideoId: youtubeKey, playerVars: playvarsDic)
Objective-C:
NSDictionary *playvarsDic = @{ @"controls" : @1, @"playsinline" : @1, @"autohide" : @1, @"showinfo" : @1, @"autoplay": @1, @"modestbranding" : @1 };
[YoutubePlayer loadWithVideoId:newString playerVars: playvarsDic
Since the variables are kind of confusing, I listed what each variable means here:
-
controls
This parameter indicates whether the video player controls are displayed controls=0 – Player controls do not display in the player. controls=1 (default) – Player controls display in the player. -
playsinline
This parameter controls whether videos play inline or fullscreen in an HTML5 player on iOS. Valid values are 0:This value causes fullscreen playback. This is currently the default value, though the default is subject to change. 1: This value causes inline playback for UIWebViews created with the allowsInlineMediaPlayback property set to TRUE. -
autohide
The autohide parameter has been deprecated for the HTML5 player since August 19, 2015. In HTML5 players, the video progress bar and player controls display or hide automatically. That behavior corresponds to an autohide setting of 1. -
showinfo
Supported values are 0 and 1. Setting the parameter's value to 0 causes the player to not display information like the video title and uploader before the video starts playing. If the player is loading a playlist, and you explicitly set the parameter value to 1, then, upon loading, the player will also display thumbnail images for the videos in the playlist. Note that this functionality is only supported for the AS3 player. -
autoplay
This parameter specifies whether the initial video will automatically start to play when the player loads. Supported values are 0 or 1. The default value is 0 -
modestbranding
This parameter lets you use a YouTube player that does not show a YouTube logo. Set the parameter value to 1 to prevent the YouTube logo from displaying in the control bar. Note that a small YouTube text label will still display in the upper-right corner of a paused video when the user's mouse pointer hovers over the player.
Source: https://developers.google.com/youtube/player_parameters P.S. The link is correct, but somehow it redirect to 404 of github. Perhaps copy paste the link will work.
playsinline
parameter does work. Shouldn't it rather be set to 1
by default?
@csbubbles You can take a look at this. Youtube had defined the parameters already. I don't think we can change it here. https://developers.google.com/youtube/player_parameters?playerVersion=HTML5. P.S. The link is correct. If it redirect to github 404 page, try copy paste the link.
@csbubbles your last link seems to be invalid. The contest is right but the hyperlink is sending to github...
@paulincai It seems like some weird thing happens lol. Just copy paste the link then.
How to use other variables such as start
or end
that takes an Int value ? I tried to use the following but when I insert start
and end
parameters, the player stop working :
youtubePlayerView.playerVars = [
"start": 10 as AnyObject,
"end": 14 as AnyObject,
"playsinline": "0" as AnyObject,
"showinfo": "0" as AnyObject,
"controls": "1" as AnyObject,
"modestbranding": "0" as AnyObject
] as YouTubePlayerView.YouTubePlayerParameters
youtubePlayerView.loadVideoID(videoURl)
In Swift When Add YTPlayerView Object In View. And Set YTPlayerDelegate, VideoId And PlayVars. When Video Play at that time Delegate Method
"func playerView(_ playerView: YTPlayerView, didChangeTo state: YTPlayerState)"
call and state is "Buffering" i have wait for video play but after some time again call delegate method and state would be "unstarted"
This Happened in All Video URL. If Any Solution then share on post.
Try to use a real device for testing @kopsPrmr
Hope this helps : )
Swift:
let playvarsDic = ["controls": 1, "playsinline": 1, "autohide": 1, "showinfo": 1, "autoplay": 1, "modestbranding": 1]
YoutubePlayer.load(withVideoId: youtubeKey, playerVars: playvarsDic)
Objective-C:
NSDictionary *playvarsDic = @{ @"controls" : @1, @"playsinline" : @1, @"autohide" : @1, @"showinfo" : @1, @"autoplay": @1, @"modestbranding" : @1 };
[YoutubePlayer loadWithVideoId:newString playerVars: playvarsDic
Since the variables are kind of confusing, I listed what each variable means here:
controls
This parameter indicates whether the video player controls are displayed controls=0 – Player controls do not display in the player. controls=1 (default) – Player controls display in the player.playsinline
This parameter controls whether videos play inline or fullscreen in an HTML5 player on iOS. Valid values are 0:This value causes fullscreen playback. This is currently the default value, though the default is subject to change. 1: This value causes inline playback for UIWebViews created with the allowsInlineMediaPlayback property set to TRUE.autohide
The autohide parameter has been deprecated for the HTML5 player since August 19, 2015. In HTML5 players, the video progress bar and player controls display or hide automatically. That behavior corresponds to an autohide setting of 1.showinfo
Supported values are 0 and 1. Setting the parameter's value to 0 causes the player to not display information like the video title and uploader before the video starts playing. If the player is loading a playlist, and you explicitly set the parameter value to 1, then, upon loading, the player will also display thumbnail images for the videos in the playlist. Note that this functionality is only supported for the AS3 player.autoplay
This parameter specifies whether the initial video will automatically start to play when the player loads. Supported values are 0 or 1. The default value is 0modestbranding
This parameter lets you use a YouTube player that does not show a YouTube logo. Set the parameter value to 1 to prevent the YouTube logo from displaying in the control bar. Note that a small YouTube text label will still display in the upper-right corner of a paused video when the user's mouse pointer hovers over the player.Source: https://developers.google.com/youtube/player_parameters P.S. The link is correct, but somehow it redirect to 404 of github. Perhaps copy paste the link will work.
Thanks for the help. but I need to auto play the player from the beginning. can it be possible?