在统一编辑器或统一应用程序(Windows独立应用程序)上播放某些视频时遇到问题。 视频文件的音频不稳定。
如果我使用任何播放器在Windows上播放录制的视频文件,则不会出现问题。
在处理完这个问题之后,我想我已经找到了问题:录制视频的音频持续时间大于自身视频的持续时间。
您可以查看普通视频和录制视频的详细信息。
普通视频详情: https://drive.google.com/file/d/1qzKSr-Fb2ohb2W1xwooZum0xT3acQZM4/view?usp=sharing
录制的视频详情: https://drive.google.com/file/d/1jpr2IJwtIByLsWh7itVfm0nhoprarNm4/view?usp=sharing
我的问题是两部分:
1-持续时间的差异是否可以解决这个问题。
2-如何统一解决这个问题?
private IEnumerator PlayVideo(string filePath)
{
//Add VideoPlayer to the GameObject
_videoPlayer = gameObject.AddComponent<VideoPlayer>();
//Add AudioSource
_audioSource = gameObject.AddComponent<AudioSource>();
//Disable Play on Awake for both Video and Audio
_videoPlayer.playOnAwake = false;
_audioSource.playOnAwake = false;
_audioSource.Pause();
//We want to play from video clip not from url
//videoPlayer.source = VideoSource.VideoClip;
// Vide clip from Url
_videoPlayer.source = VideoSource.Url;
_videoPlayer.url = filePath;
//Set Audio Output to AudioSource
_videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
//Assign the Audio from Video to AudioSource to be played
_videoPlayer.controlledAudioTrackCount = 1;
_videoPlayer.EnableAudioTrack(0, true);
_videoPlayer.SetTargetAudioSource(0, _audioSource);
//Set video To Play then prepare Audio to prevent Buffering
//videoPlayer.clip = myVideoClip;
_videoPlayer.Prepare();
//Wait until video is prepared
WaitForSeconds waitTime = new WaitForSeconds(1);
_retryCount = 0;
while (!_videoPlayer.isPrepared)
{
Debug.Log("Preparing Video");
//Prepare/Wait for 15 sceonds only
yield return waitTime;
_retryCount++;
if (_retryCount >= _maximumRetries)
{
break;
}
}
_vidFrameLength = (int)_videoPlayer.frameCount;
ProgressBar.maxValue = _vidFrameLength;
Debug.Log("Done Preparing Video");
VideoPlayerImage.texture = _videoPlayer.texture;
_videoPlayer.Play();
_audioSource.Play();
ClipLength.text = StringHelper.ToTime((float)_videoPlayer.frameCount / _videoPlayer.frameRate, TimePreviewer.Minutes);
while (_videoPlayer.isPlaying)
{
yield return null;
}
}
答案 0 :(得分:1)
目前,我在Unity商店发现了2个视频播放器库,可以毫无问题地播放不连贯的视频。
我正在使用其中一个,直到Unity解决了播放可变帧速率视频的问题。
https://assetstore.unity.com/packages/tools/video/ump-win-mac-linux-webgl-49625 https://assetstore.unity.com/packages/tools/video/avpro-video-windows-57969
我知道这不是问题的解决方案,但是直到有人对这个问题给出了一个很好的答案,我将使用它。
答案 1 :(得分:0)
假设您正在使用VideoPlayer组件尝试更改 从AudioSource到Direct的音频输出模式反之亦然,看看它是否有所改变。
答案 2 :(得分:0)
尝试将audiousource加载类型修改为&#34; steaming&#34;检查员。