youtube / youtube-ios-player-helper

Lightweight helper library that allows iOS developers to add inline playback of YouTube videos through a WebView
Other
1.65k stars 684 forks source link

YouTube always expands to full screen when starts playing #292

Open csbubbles opened 6 years ago

csbubbles commented 6 years ago

Xcode: 9.1 (9B55) iOS: 11.1 YouTube iOS Player: pod "youtube-ios-player-helper", "~> 0.1.6"

Repro steps

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.

MamdouhRElNakeeb commented 6 years ago

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

sunnyleeyun commented 6 years ago

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.

csbubbles commented 6 years ago

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

sunnyleeyun commented 6 years ago

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

paulincai commented 6 years ago

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

sunnyleeyun commented 6 years ago

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

anthorn69 commented 6 years ago

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)
kopsPrmr commented 6 years ago

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.

anthorn69 commented 6 years ago

Try to use a real device for testing @kopsPrmr

01234abhishek commented 3 years ago

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?