Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug that full screen playback is not possible on iPad #452

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

harumidiv
Copy link

Overview

Fixed it not working when tapping the default full screen button on the iPad.

Copy link

@NarongOk NarongOk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solve iPad full issue

@gsl-adriensimon
Copy link

When will these changes be released?

andriypohorilko added a commit to andriypohorilko/youtube-ios-player-helper that referenced this pull request Jun 4, 2022
@Janneman84
Copy link

Janneman84 commented Mar 17, 2023

This 'fix' makes videos always play full screen, instead of optional...

Instead I found a workaround to fool YouTube by creating a small UIWindow (375x375pt) and add the YT player as a subview to that window (same size). After the video is loaded (using the delegate callback) I move the player view to my desired view by simply using addSubview(). You don't have to make the UIWindow visible, just keep a reference to it so it won't deinit (i.e. a VC property).

I noticed when you use iPad split screen and make the app as thin as possible then the YT player does allow full screen (but only when it starts when thin). When you make it big again the full screen button keeps working. This helped me realize it may be possible to trick YT like I explained above, which works :).

I found that 375pt is the threshold, if you make the UIWindow 376pt the full screen button stops working.

If interested I can show some code.

rafalwojcik pushed a commit to rafalwojcik/youtube-ios-player-helper that referenced this pull request Aug 30, 2023
add player volume methods

Update README.md

Add macOS support mention

fixed playing on iOS until this pull request is merged: youtube#452

add set / get volume
@aryanarayantiwari
Copy link

aryanarayantiwari commented Oct 3, 2023

This 'fix' makes videos always play full screen, instead of optional...

Instead I found a workaround to fool YouTube by creating a small UIWindow (375x375pt) and add the YT player as a subview to that window (same size). After the video is loaded (using the delegate callback) I move the player view to my desired view by simply using addSubview(). You don't have to make the UIWindow visible, just keep a reference to it so it won't deinit (i.e. a VC property).

I noticed when you use iPad split screen and make the app as thin as possible then the YT player does allow full screen (but only when it starts when thin). When you make it big again the full screen button keeps working. This helped me realize it may be possible to trick YT like I explained above, which works :).

I found that 375pt is the threshold, if you make the UIWindow 376pt the full screen button stops working.

If interested I can show some code.

Hi! @Janneman84 can you please share some code for what you just specified ?

@Janneman84
Copy link

Janneman84 commented Oct 4, 2023

Hi! @Janneman84 can you please share some code for what you just specified ?

Inside ViewController declare:

private var hackWindow: UIWindow?

Initiate the player like this:

if (UIDevice().userInterfaceIdiom == .pad) {
    let playerView = YTPlayerView(frame: CGRect(x: 0, y: 0, width: 375, height: 375))
    hackWindow = UIWindow.init(frame: playerView.frame)
    hackWindow!.addSubview(playerView)
    playerView.delegate = self
    playerView.load(...)
}

Implement delegate method like this:

func playerViewDidBecomeReady(_ playerView: YTPlayerView) {
    if let hackedPlayerView = hackWindow?.subviews.first as? YTPlayerView, hackedPlayerView == playerView {
        hackedPlayerView.frame = myVideoView.bounds
        myVideoView.addSubview(hackedPlayerView)
        hackWindow = nil
    }
    playerView.playVideo()
}

I haven't tested this exact code but you get the idea. In the delegate you can add/insert the player view wherever you want.

@aryanarayantiwari
Copy link

Hi! @Janneman84 can you please share some code for what you just specified ?

Inside ViewController declare:

private var hackWindow: UIWindow?

Initiate the player like this:

if (UIDevice().userInterfaceIdiom == .pad) {
    let playerView = YTPlayerView(frame: CGRect(x: 0, y: 0, width: 375, height: 375))
    hackWindow = UIWindow.init(frame: playerView.frame)
    hackWindow!.addSubview(playerView)
    playerView.delegate = self
    playerView.load(...)
}

Implement delegate method like this:

func playerViewDidBecomeReady(_ playerView: YTPlayerView) {
    if let hackedPlayerView = hackWindow?.subviews.first as? YTPlayerView, hackedPlayerView == playerView {
        hackedPlayerView.frame = myVideoView.bounds
        myVideoView.addSubview(hackedPlayerView)
        hackWindow = nil
    }
    playerView.playVideo()
}

I haven't tested this exact code but you get the idea. In the delegate you can add/insert the player view wherever you want.

Thanks! this works perfectly.

@kunalsood
Copy link

Hi! @Janneman84 can you please share some code for what you just specified ?

Inside ViewController declare:

private var hackWindow: UIWindow?

Initiate the player like this:

if (UIDevice().userInterfaceIdiom == .pad) {
    let playerView = YTPlayerView(frame: CGRect(x: 0, y: 0, width: 375, height: 375))
    hackWindow = UIWindow.init(frame: playerView.frame)
    hackWindow!.addSubview(playerView)
    playerView.delegate = self
    playerView.load(...)
}

Implement delegate method like this:

func playerViewDidBecomeReady(_ playerView: YTPlayerView) {
    if let hackedPlayerView = hackWindow?.subviews.first as? YTPlayerView, hackedPlayerView == playerView {
        hackedPlayerView.frame = myVideoView.bounds
        myVideoView.addSubview(hackedPlayerView)
        hackWindow = nil
    }
    playerView.playVideo()
}

I haven't tested this exact code but you get the idea. In the delegate you can add/insert the player view wherever you want.

This workaround no longer seems to be working, at least for me.
Can anyone please confirm? @Janneman84 @aryanarayantiwari

@Janneman84
Copy link

I don't have an iOS18 iPad, but in simulator the full screen button still works in my app.

@kunalsood
Copy link

I don't have an iOS18 iPad, but in simulator the full screen button still works in my app.

Sorry, my bad, I was trying this on a Mac Catalyst app. It does indeed continue to work on iPad apps.
Thanks for confirming @Janneman84

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants