- Home /
Unity iOS: Set Orientation for Handheld.PlayFullScreenMovie
Hi,
I am using following code to quickly switch from Portrait to landscape before playing video and then again back to portrait after video playing done.
IEnumerator playVideo() {
Screen.orientation = ScreenOrientation.Landscape;
yield return new WaitForSeconds(.1f);
yield return new WaitForEndOfFrame();
Handheld.PlayFullScreenMovie (background_.lastTrackableVideoPath_, Color.black, FullScreenMovieControlMode.Full, FullScreenMovieScalingMode.AspectFit);
Screen.orientation = ScreenOrientation.Portrait;
yield return new WaitForSeconds(.1f);
}
Above code is not working and video is always played in portrait. I have iOS 6.0.
Any idea why this is happening?
hey @Deathfate can you help please ? i am unable to play video horizontally.. actually video played horizontally but when it close UI is disturbed.
here is ur solution i tried. http://answers.unity3d.com/questions/544848/unity-ios-set-orientation-for-handheldplayfullscre.html
thanks
Thats why I used a black image in between because the ui messes up in between the switch from portrait to landscape.
Create a Black image that fills all the screen then activate it before switching to landscape, then wait a frame, then play the video, and then switch back to portrait, wait a frame and then deactivate the black image
You can see in my answer below that I use blackbgImage.SetActive (true); and blackbgImage.SetActive (false); thats my back image that fills all the canvas and its on top of everything.
Answer by Deathfate · Jan 15, 2016 at 05:45 PM
In my case I had a portrait app and wanted to play the video in landscape. I managed to solve it this way:
protected IEnumerator PlayBackRoutine(){
blackbgImage.SetActive (true);
Screen.orientation = ScreenOrientation.Landscape;
while (Screen.currentResolution.height > Screen.currentResolution.width) {
yield return null;
}
Handheld.PlayFullScreenMovie ("http://videourl.mp4");
yield return null;
Screen.orientation = ScreenOrientation.Portrait;
while (Screen.currentResolution.height < Screen.currentResolution.width) {
yield return null;
}
blackbgImage.SetActive (false);
}
I created a black image that occpies all the screen called blackbgImage. So i show it before changing to landscape, switch to landscape, wait until the switch is done, play the video, wait 1 frame, switch to portrait, wait until the switch is done and unshow the image.
The result is super neat, i couldnt notice the difference between this and a native app.
Answer by Visual Programmer · Sep 28, 2013 at 04:02 PM
Try using LandscapeLeft or LandscapeRight. Landscape is not a valid ScreenOrientation.
Answer by qoobit · Mar 10, 2015 at 02:40 PM
You need to put two copies of
yield return new WaitForEndOfFrame();
After the PlayFullScreenMovie or else it will switch to portrait before the video finishes.