Home >Backend Development >C++ >Why Isn't My Unity Video Playing Audio After Upgrading to 5.6.0b1?
Solve the video playback without audio problems after the upgrade of Unity 5.6.0B1
Question: After upgrading to Unity 5.6.0B1, in the UNITY editor of Windows 10, there is no audio for video playback.
Solution:
The problem originated from the order of operation. To successfully play videos and audio, you must follow the following code order:Code after the correction:
The key step is to set the audio output mode and the audio track configuration before preparing the video
. This ensures that the audio can be played correctly. Failure to exclude other problems:
<code class="language-c#">// 添加VideoPlayer和AudioSource组件 videoPlayer = gameObject.AddComponent<VideoPlayer>(); audioSource = gameObject.AddComponent<AudioSource>(); // 对两个组件禁用“Play on Awake” videoPlayer.playOnAwake = false; audioSource.playOnAwake = false; // 设置视频源为VideoClip和音频输出模式 videoPlayer.source = VideoSource.VideoClip; videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource; // 配置音频轨道 videoPlayer.EnableAudioTrack(0, true); videoPlayer.SetTargetAudioSource(0, audioSource); // 设置视频剪辑并准备播放器 videoPlayer.clip = videoToPlay; videoPlayer.Prepare(); // 等待视频准备完成 WaitForSeconds waitTime = new WaitForSeconds(5); while (!videoPlayer.isPrepared) { Debug.Log("正在准备视频"); yield return waitTime; break; } // 将视频纹理分配给RawImage image.texture = videoPlayer.texture; // 播放视频和音频 videoPlayer.Play(); audioSource.Play();</code>
Card "is preparing video"? After calling , wait for 5 seconds, and then exit the cycle.
Can't play the video from the URL? Make sure the URL is correct and supports the video format.
Unswerving video format:The above is the detailed content of Why Isn't My Unity Video Playing Audio After Upgrading to 5.6.0b1?. For more information, please follow other related articles on the PHP Chinese website!