[英]How can i rotate screen when use video player full screen in unity?
I'm working on application in unity3d and my orientation is portrait.我正在开发 unity3d 中的应用程序,我的方向是纵向。 So when i play video on fullscreen mode with :所以当我在全屏模式下播放视频时:
Handheld.PlayFullScreenMovie(vClip, Color.black, FullScreenMovieControlMode.Full);
my video play on fullscreen but in portrait.But i want play it in landscape mode.我的视频以全屏模式播放,但以纵向模式播放。但我想以横向模式播放。 I try:我尝试:
public void PlayVideo()
{
StartCoroutine(PlayFullVideoCoroutine());
Screen.orientation = ScreenOrientation.LandscapeLeft;
print("Play Full Video Coroutine!");
}
IEnumerator PlayFullVideoCoroutine()
{
Handheld.PlayFullScreenMovie(vClip, Color.black, FullScreenMovieControlMode.Full);
yield return new WaitForEndOfFrame();
Screen.orientation = ScreenOrientation.Portrait;
print("Full Video Playback Completed.");
}
It's working but when video finish , the application orientation don't change to portrait.它正在工作,但是当视频完成时,应用程序方向不会更改为纵向。 Any help please.请任何帮助。
So I experimented with Handheld.PlayFullScreenMovie and as is stated in the documentation:所以我尝试了Handheld.PlayFullScreenMovie并如文档中所述:
Calling this function will pause Unity during movie playback.调用此函数将在电影播放期间暂停 Unity。 When playback finishes Unity will resume.播放完成后,Unity 将恢复。
This is an indication of a timing issue .这是时序问题的指示。 So I setup the following code:所以我设置了以下代码:
using System.Collections;
using UnityEngine;
public class Testy : MonoBehaviour
{
void Start()
{
StartCoroutine(PlayVideo());
}
public IEnumerator PlayVideo()
{
Screen.orientation = ScreenOrientation.LandscapeLeft;
yield return new WaitForSeconds(1f);
Handheld.PlayFullScreenMovie("video.mp4", Color.black, FullScreenMovieControlMode.Full);
yield return new WaitForSeconds(1f);
Screen.orientation = ScreenOrientation.Portrait;
}
}
In my experiment I found that if I added a one second wait after setting the orientation using Screen.orientation
it would work, but if I only waited a single frame it wouldn't.在我的实验中,我发现如果我在使用Screen.orientation
设置方向后添加一秒等待它会起作用,但如果我只等待一帧它就不会。
Add a yield return new WaitforSeconds(1f)
after changing the orientation to ensure the orientation is changed.更改方向后添加yield return new WaitforSeconds(1f)
以确保更改方向。 I know this isn't the most pretty code but it seems to do the job.我知道这不是最漂亮的代码,但它似乎可以完成这项工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.