我在Unity编辑器或Unity应用程序(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;
}
}
假设您正在使用VideoPlayer组件尝试更改音频输出模式从AudioSource到Direct Vise Verna,以查看是否会改变某物。
目前,我在Unity商店中发现了2个视频库,它们播放了无聊的视频而没有问题。
我正在使用其中一个,直到Unity解决了有关播放可变帧速率视频的问题。
https://assetstore.unity.com/packages/tools/video/ump-win-mac-linux-webgl-49625https://assetstore.unity.com/packages/tools/video/avpro-video-windows-57969
我知道这不是解决问题的解决方案,但是直到任何人对问题给出一个很好的答案,我将使用此问题。
尝试将iuiousource加载类型修改为"蒸"。