Orientation Issue in AVPlayerViewController

Hi,


I am facing issue in AVPlayerViewController that when I am changing orientation my video is not rotating in upsidedown orientation. It is rotating in Portrait and Landsscape except Portrait UpSide Down. So help me how to fix this issue.


Thanks

Warm Regards

This will not be possible on iPhone X (or any future notched iPhone).


For other phones, maybe you need to override supportedInterfaceOrientations (by default, allButUpsideDown: upside down is off). :


    override open var supportedInterfaceOrientations : UIInterfaceOrientationMask     { 
        return .all 
    }


See this other thread : h ttps://forums.developer.apple.com/message/314009#314009

Hi,


Thanks for reply. I am checking this on iPhone 6s and 6S Plus Devices. Please help me out how I can acheive this. Becuase all three orientations are working Fine means Portarait, Both Landscape only PortraitUpSIdeDown is not working. When I zooming my video with AVPlayerController even Status Bar is rotating but my video and Player controls are not rotating.


Thanks

Warm Regards

You need to check:


- in info.plist, that all 4 orientations are supported

- in the UIViewController, add

    override open var supportedInterfaceOrientations : UIInterfaceOrientationMask     {
        return .all
    }


If you have NavigationController or TabBarController, need to define those extensions as well :

extension UINavigationController {
    override open var supportedInterfaceOrientations : UIInterfaceOrientationMask     {
        return .all
    }
}

extension UITabBarController {
    override open var supportedInterfaceOrientations : UIInterfaceOrientationMask     {
        return .all
    }
}


Could you show the code of your AVPlayerController ?

Maybe you have to include this supportedInterfaceOrientations here as well.

Hi,


I have Used Below Code.

override open var supportedInterfaceOrientations : UIInterfaceOrientationMask     { 
        return .all 
    }


also in Info.plist I added values but still same issue no orientation support for portraitUpsideDown.

            self.avpController = AVPlayerViewController()
            videoHolderView?.isHidden = false
            print("Supported Orientation \(self.avpController.supportedInterfaceOrientations)")
            self.player = AVPlayer(url: URL(fileURLWithPath: path))
            self.avpController.player = self.player
            avpController.showsPlaybackControls = true
            avpController.view.frame = CGRect(x: 0.0, y: 0.0, width: videoHolderView.frame.size.width, height: videoHolderView.frame.size.height)
            self.addChildViewController(avpController)
            avpController.view.backgroundColor = StyleKit.contentBGColor
            videoHolderView?.addSubview(avpController.view)
            self.player?.play()
            self.player?.isMuted = true


above is my code. Please check this.


Thanks

Warm Regards

What do you get for the print:


            print("Supported Orientation \(self.avpController.supportedInterfaceOrientations)")


Did you try to include :


self.avpController.supportedInterfaceOrientations = .all

Hi,




Supported Orientation -> UIInterfaceOrientationMask(rawValue: 30)

I have tried both but these are not working. When I click for zoom video then it show full screen and all orientation working fine except PortraitUpSideDown. Please tell me some other things which I can try and solve this issue.


this is not supporting

self.avpController.supportedInterfaceOrientations = .all


giving error

Cannot assign to property: 'supportedInterfaceOrientations' is a get-only property


Thanks


Warm Regards

30 means all orinetations are supported.

I don't remember well, but I wonder if AVPlayer supports upsideDown.



So, maybe you just want to rotate the video after testing orientation


For testing orientation, see this:

h ttps://stackoverflow.com/questions/41659646/get-the-current-device-orientation


for rotating AVPlayer

h ttps://stackoverflow.com/questions/38736273/how-to-change-video-orientation-of-avplayer

Hi,


Thanks for replying me. I am able to get current device oreintation with "NSNotification.Name.UIDeviceOrientationDidChange" and in portraitUpsideDown condition I also tried that method which is provided in above link. So when I trying below method from above link

func rotateVideoPlayer(player: AVPlayer, degrees: CGFloat) -> AVPlayer? { ... }

it is rotating my video in upsidedown but player controls are not rotating like Play, close and seek bar all are in portrait mode. they are not rotating. Can you please tell me some other information which I can check.


Thanks

There is a similar case with tabBarController or NavigationControllers.


In that case, it is required to add extensions I described before


extension UINavigationController {
    override open var supportedInterfaceOrientations : UIInterfaceOrientationMask     {
        return .all
    }
}

extension UITabBarController {
    override open var supportedInterfaceOrientations : UIInterfaceOrientationMask     {
        return .all
    }
}


So, try adding this extension

extension AVPlayerViewController {
    override open var supportedInterfaceOrientations : UIInterfaceOrientationMask     {
        return .all
    }
}

Hi,


Thanks for this but It is also not working. I Have tried everything. so what is happening in my view controller I have a view named videoHolderView in which I am adding AVPlayerViewController like this.

videoHolderView?.addSubview(avpController.view)


so when I navigate to this current VIew controller all is working fine means it is rotating in all orientation. The problem is, when I am clicking for Zoom via AVPlayerController controls, it is zoomed to full screen and now if I am rotating to portraitUpSideDown then my viewcontroller's view is rotating becuase status display in portraitUpsideDownOrientation but only issue is with AVPlayerController and it's player. Both are not rotating. If some how I am able to rotate this avplayer video then play, pause controls not rotating. so this is becoimg big issue for me.

Becuase View Controller is rotaitng but AVPlayerController with AVPlayer is not rotating.

I have tried all things which is mentioned above. Please help me out.


Thanks

Warm Regards

When in zoom mode, does rotate to landscape work correctly ?


Do you test on simulator or on real device (not iPhone X), or both ? Do you face problem in all those cases ?


To try to help further, I would need to test your code.

If you want to send your email, I will give you mine so that you can send me the whole project, if you wish.

Hi,


When in zoom mode, does rotate to landscape work correctly ? --> Yes It is working fine in landscape mode.

I have test this in iPhone 6S.

Sorry to say but I can not share my source code but for the same I have creatd a sample application and same issue I am facing in that like working in View but when I zoom not working in portraitUpsidedown mode. I can send you that please provide me your mail id.


Thanks

Warm Regards

Hi,


Still I did not get any solution for this oreintatoin issue so If some one have any soulution then please let me know.


Thanks

Warm Regards

Orientation Issue in AVPlayerViewController
 
 
Q