【问题标题】:How can i rotate screen when use video player full screen in unity?统一使用视频播放器全屏时如何旋转屏幕?
【发布时间】:2020-03-02 01:56:10
【问题描述】:

我正在开发 unity3d 中的应用程序,我的方向是纵向的。 所以当我在全屏模式下播放视频时:

Handheld.PlayFullScreenMovie(vClip, Color.black, FullScreenMovieControlMode.Full);

我的视频以全屏模式播放,但以纵向模式播放。但我想以横向模式播放。 我试试:

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.");
}

它正在工作,但是当视频结束时,应用程序方向不会变为纵向。 请帮忙。

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    所以我尝试了Handheld.PlayFullScreenMovie,正如文档中所述:

    调用此函数将在电影播放期间暂停 Unity。播放完成后,Unity 将恢复。

    这表明存在时间问题。所以我设置了以下代码:

    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;
        }
    }
    

    在我的实验中,我发现如果我在使用 Screen.orientation 设置方向后添加一秒钟的等待时间,它会起作用,但如果我只等待一帧,它就不会。

    解决办法

    更改方向后添加yield return new WaitforSeconds(1f),以确保更改方向。我知道这不是最漂亮的代码,但它似乎可以完成这项工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-28
      • 2011-07-10
      • 1970-01-01
      • 1970-01-01
      • 2013-12-21
      • 2010-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多