Handle video player orientation change like YouTube app - ios

I would like to know the best way to handle the device orientation change while viewing a video like how it works in the YouTube app. In landscape, the video is full screen but when the user rotates to portrait the video is pinned to top of screen and a list of 'recommended' videos are listed below it. How can I achieve this? Any help would be greatly appreciated. Thanks in advance.

Youtube only takes care the orientation when rotation of device is unlock.
If you want to do like this, implement this function
(void)willAnimateRotationToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
to handle when orientation changes.

Related

Add scroll playback controls to AVPlayer like in Photos app

I'm creating AVPlayer view to watch the stream from CCTV. And I want to make playback controls in a video like in Photos app at iPhone(open Photos, play some video, at the bottom, it will be UIScrollView with some screenshots of your video) like at image below.
May I ask you some help on how to create something like this?
And this is my first question here, so sorry if something wrong. =)
ScrollView playback
AVPlayer cannot do this for streaming. The suggestion made on snapshots would also not be close to your want of getting the same behaviour as on local preview of videos in the Photos App on iOS.
If you are looking for this kind of experience I would recommend heading over to movi.ai to get your hands on our cross platform solution with this ready out of the box.

How to rotate a player view like what Youtube app does

Here is my app:
Screen record
But the animation is autorotation default. It's not looking very smooth. I want my video player rotate and expend to whole screen like what Youtube iOS app does. How to do that? Any suggestion?
Actually it seems only the video player view is rotated and expanded to full screen for Youtube App. But the whole view of UIViewController is rotated in my case.

How to implement apple like camera app using AVCaptureSession?

In the iOS(9) camera app the controls overlay does not rotate but when 'Record' is selected the video is outputted with the correct orientation. Has anyone got any ideas how apple implemented this.
You've got a few different options to achieve the same effect:
You can rotate the camera, but keep the UI the same, when the device itself is rotated so that it matches UIDevice.currentDevice().orientation.
You could store the device orientation at the time of capture and then rotate the video afterwards.
You could even set the capture connection of the capture session to match the devices orientation while keeping the preview connection the same. Check this out for a similar question
I implemented exactly what you're looking for using 2 different UIWindow instances, one for the video preview layer and one for the UI to be displayed on top of it. The UIWindow with the UI needs to have a transparent background in order for the preview layer to remain visible.

Layout Constraints Only Applied In Certain Conditions When Size Class Changes

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

MPMoviePlayerViewController plays recorded portrait movie rotated

I have a problem with the MPMoviePlayerViewController (I use the shortcut MPVC) playing recorded portrait movies right.
(Tested on iPhone 4S with iOS 6.0.1)
The app does this:
Record a movie (landscape or portrait)
Preview the movie in MPC (this time MPMoviePlayerController)
Upload the movie
There is a tableView of uploaded movies, where you can watch them
Watching the movie is done by MPVC
If I record a movie in portrait mode, the MPVC plays this video flipped to the right.
Something similar happens if I record the movie in landscape mode right (home button on the left), then the movie is played upside down in MPVC.
This only happens when playing the movie after uploading it! In the preview MPC, the movie just plays fine and not rotated!
I found some related SO questions involving rotated videos, but none are related explicitly to MPVC.
I used this and found out that the orientation stored in the movie is perfectly correct. So portrait movies really return UIInterfaceOrientationPortrait with this Method.
So now my question is, is there a way to tell the MPVC to rotate the movie or treat it right? Or do I have to write my own player based on AVFoundation?
Is this a MPVC bug, because the orientation information the movie provides seem to be correct?
I've recently stumbled upon similar issue where my videos were forced into landscape orientation after I uploaded them to 3rd party CDN. It turned out they were blindly "flipped" by 3rd party service to the landscape orientation and converted into iOS stream resource. There's probably nothing wrong with your videos, just make sure you understand what processes are in place after you've uploaded them because that might have been the case.
After having a long conversation with my CDN hosting provider, they confirmed an issue :
"The problem is that the trans-coding from the file in Cloud Files to an iOS stream seems to lose the EXIF information about orientation so it just displays as landscape."
The solution suggested was to rotate the video before uploading it.

Resources