youtube-ios-player-helper icon indicating copy to clipboard operation
youtube-ios-player-helper copied to clipboard

YouTube always expands to full screen when starts playing

Open csbubbles opened this issue 7 years ago • 10 comments

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 to YTPlayerView; add appropriate constrains (e.g., left, top, right and height/width proportion)
  • Connect the view to playerView field in ViewController.swift
  • Add playerView.load(withVideoId: "M7lc1UVf-VE") to the end of viewDidLoad() method in ViewController.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.

csbubbles avatar Nov 13 '17 09:11 csbubbles

This fixed the issue for me, it controls the embedded webView and play it inline. youtubePlayer.load(withVideoId: videoID, playerVars: ["playInline" : 1])

MamdouhRElNakeeb avatar Dec 25 '17 18:12 MamdouhRElNakeeb

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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
  6. 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.

sunnyleeyun avatar Dec 29 '17 07:12 sunnyleeyun

playsinline parameter does work. Shouldn't it rather be set to 1 by default?

csbubbles avatar Jan 08 '18 00:01 csbubbles

@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.

sunnyleeyun avatar Jan 10 '18 08:01 sunnyleeyun

@csbubbles your last link seems to be invalid. The contest is right but the hyperlink is sending to github...

paulincai avatar Jun 05 '18 16:06 paulincai

@paulincai It seems like some weird thing happens lol. Just copy paste the link then.

sunnyleeyun avatar Jun 06 '18 05:06 sunnyleeyun

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)

anthorn69 avatar Aug 19 '18 19:08 anthorn69

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.

kopsPrmr avatar Aug 22 '18 07:08 kopsPrmr

Try to use a real device for testing @kopsPrmr

anthorn69 avatar Aug 22 '18 08:08 anthorn69

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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
  6. 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.

Thanks for the help. but I need to auto play the player from the beginning. can it be possible?

01234abhishek avatar Dec 11 '20 11:12 01234abhishek