3

I am using the YouTubePlayer from here. Everything works fine except on loading and changing of orientation there is some showing of white view. On loading there is a white screen before the player is ready. On changing of orientation while the device is rotating white view is displayed behind the player. Any way to correct this?

What I tried so far is:
1. Changing the background colour from IB.
2. Changing the background colour from the code in viewDidLoad
3. Adding "theme" : "dark" as AnyObject in playerVars.

surToTheW
  • 772
  • 2
  • 10
  • 34
  • Did you change color of your view's background? – Ladislav May 01 '18 at 14:18
  • @Ladislav Yes I tried that, but it's not helping – surToTheW May 01 '18 at 15:31
  • Did you try setting the background color of `YouTubePlayerView` – Ladislav May 01 '18 at 15:38
  • @Ladislav - Yes, I did, no luck – surToTheW May 02 '18 at 07:25
  • 1
    Try adding a `layer` or a `view` to the `YouTubePlayerView` by inserting it at index 0... – Ladislav May 02 '18 at 07:29
  • @Ladislav I tried them both - the weird thing is that they have no effect at all, not just that they are not solving the issue. I am not very sure what is happening. – surToTheW May 02 '18 at 07:59
  • Try to explore view hierarchy by tapping `Debug View Hierarchy` in Xcode debug area after running the app and when youtube player shows up – Ladislav May 02 '18 at 08:46
  • @Ladislav Your suggestions brought me into a right direction. The library is removing and adding again the `web view` in `layoutSubviews` every time. So I made changes to colours in `viewWillLayoutSubviews` and `viewDidLayoutSubviews` in the `ViewController`. That almost solved it and the last step was to go to the HTML file of the library and do this: https://github.com/gilesvangruisen/Swift-YouTube-Player/issues/25 Still this is a change to the library itself and doesn't seem like a good idea. So I am still a bit stuck. Thanks for the input. – surToTheW May 02 '18 at 09:21

2 Answers2

3

Call playerViewPreferredWebViewBackgroundColor method from WKYTPlayerViewDelegate's methods and set clear color

func playerViewPreferredWebViewBackgroundColor(_ playerView: WKYTPlayerView) -> UIColor {
    return .clear
}
Asha Patel
  • 31
  • 3
0

Set the background color of the underlying parent view, either in Interface Builder, or in code, in viewDidLoad:

self.view.backgroundColor = UIColor.black //whatever color you what
rbaldwin
  • 4,581
  • 27
  • 38
  • I don't think I have direct access to it. I tried with `myView.superview` and `myView.superview.superview.backgroundColor = .black`, but no change – surToTheW May 01 '18 at 15:32
  • Have you tried my exact code in your `viewDidLoad` ? – rbaldwin May 01 '18 at 15:35
  • Either that or you are referring to LaunchScreen.storyboard which by default is white and is displayed when the app is loading. If that is the case, just select LaunchScreen.storyboard and set the background color of that in interface builder. – rbaldwin May 01 '18 at 15:44
  • 1
    I've tried the YouTubePlayer pod myself now, and I can see what you mean about the white background on device rotation. I can't seem to find a way to set the background of that view either. Perhaps raise an issue on the project GitHub https://github.com/gilesvangruisen/Swift-YouTube-Player/issues – rbaldwin May 01 '18 at 16:19
  • Thanks for the suggestion - I just raised an issue there – surToTheW May 02 '18 at 07:24