In my app I want a video to open in landscape mode when the MediaPlayer is being opened, but I don't want to enable landscape in all other ViewControllers. How can I programmatically achieve this using Swift?
You need to declare method viewWillTransitionToSize:withTransitionCoordinator: in your view controller, and change frame relatively to your needs.
In more detail, you need to read here, at least.
Related
I have a camera view based on AVFoundation. Any idea how I can switch to Portrait Effect in iOS's Control Center like SnapChat?
You need to opt-in your app by adding an Info.plist key called NSCameraPortraitEffectEnabled, with boolean type set to YES.
I have created instance of AVPlayer and playing content in it. I need to provide one option to show this movie in full screen. Does any other option present instead of creating instance of AVPlayerController and using native playback button options.
AVPlayer is containing only video view. Buttons and basically all the UI over the video are responsibility of developer.
So you need to do view controller that have view where AVPLayer will be embedded, and over it another views (like buttons, labels). And of course rig everything with constraints. When you tap "full screen" button, animate constraints so you resize your video. This is it.
Much simpler (considering lines of code that must be written) is to use AVPLayerViewController, but you loose possibility of custom UI. On other hand most of the logic is there. (except for support HLS EVENT type playlists that are not closed, there is a bug that will be fixed in iOS11)
Update:
Bug in AVPLayerViewController, regarding HLS EVENT type is fixed in iOS11.
I have a container view controller which contains 2 views. One is a video and the other is chat. In portrait mode, the user can see both the video and the chat; however, in landscape, I want it to only show the video.
What I've done:
I use size classes and for wCompact and hCompact (iPhone 6 landscape), I remove the chat view and update the constraints. It 'partially' works.
If I start my application in landscape, the video will be shown in full. When I rotate to portrait, I get both the video and chat views. Finally, if I rotate it back to landscape, I only get the video view again. This is the desired behavior. See this GIF:
The problem:
If I start the app in portrait, it shows both the video and chat view. Then, when I rotate it to landscape, the chat view is removed but the video view does not update to its new layout constraints. See the GIF below:
I suspect this has something to do with the view using a MPMoviePlayerController or the fact that it's fetching/streaming data. I don't know.
I'm not even sure what to google to help with this so if anyone has anything, please let me know.
Thanks much!
Solution: Use AVPlayerViewController and AVPlayer. It just works. MPMoviePlayerController is buggy
I have a UIWebView in my viewcontroller that is embedding a YouTube video and when the user clicks it, it plays the video. I want the webview to be able to rotate, but not the viewcontroller that it's being held on. Are there any solutions out there for this problem? This is an iOS6 and above supported application.
In your shouldAutorotateToInterfaceOrientation method, change the UIWebView to the new orientation, then return NO.
This way the view controller will stay the way it is, but you can do whatever you need to do to the UIWebView to make it display correctly in the new orientation.
My iPad app has the option to play videos. I use the MPMoviePlayerViewController class to play my videos.
My question is: if I want to play the videos on an attached external monitor, how do I keep the playback controls on the iPad like YouTube does? If I add the view of the MPMoviePlayerViewController 's player to the external screen's hierarchy I can play the video fine, but I now have no control over it. Is there a way to move or duplicate the view where the controls lie and place it on a view which resides on the iPad?
I'm not aware of an officially supported way of pulling out the original UI in this way. The MPMoviePlayerViewController only exposes the MPMoviePlayerController object it uses via its moviePlayer property. The MPMoviePlayerController in turn only exposes view and backgroundView, which aren't helpful for such a purpose. You could in theory inspect the subviews of the movie player's main view, find the playback controls and try to move them to the other screen. I have a feeling this will not end well though, as they're anything but static. You also never know what will happen in later iOS versions, or if they'll let your hack on the app store. It's probably less trouble to just re-do the UI yourself.
Actually controlling the video playback programmatically is straightforward - the view controller's moviePlayer implements the MPMediaPlayback protocol.