Home > Backend Development > C++ > Why Is My Unity VideoPlayer Not Playing Audio on Windows 10?

Why Is My Unity VideoPlayer Not Playing Audio on Windows 10?

Barbara Streisand
Release: 2025-01-29 10:41:09
Original
598 people have browsed it

Why Is My Unity VideoPlayer Not Playing Audio on Windows 10?

solve the problem of audio playback in the UNITY VideoPlayer on Windows 10

Unity's VideoPlayer and VideoClip API provides a powerful way to play videos in the project. However, some users have encountered audio playback problems on the desktop platform.

Problem description:

A unity developer cannot play audio when using VideoPlayer API on Windows 10, even if the video can be displayed normally.

Solution:

After investigation, it is found that the correct order of audio attributes is essential for successful audio playback. The following modification of the code fragment provided solved this problem:

By setting the audio output mode and audio track attributes before calling Prepare (), the audio playback is now enabled.

Other tips:
<code class="language-c#">// 在准备视频之前将音频输出设置为AudioSource
videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;

// 启用音频轨道并设置目标AudioSource
videoPlayer.EnableAudioTrack(0, true);
videoPlayer.SetTargetAudioSource(0, audioSource);

// 准备视频
videoPlayer.Prepare();</code>
Copy after login

If the "being preparing video" log message is retained indefinitely, please consider adding timeout to the While to prevent the script from stagnation:

  • Make sure the supported video format is compatible with your target platform. See Unity's document to obtain a complete list of support formats.
If necessary, you can use the URL format of the platform to play videos directly from the StreamingAsSETS folder folder:
<code class="language-c#">WaitForSeconds waitTime = new WaitForSeconds(5);
while (!videoPlayer.isPrepared)
{
    Debug.Log("正在准备视频");
    yield return waitTime;
    break;
}</code>
Copy after login

The above is the detailed content of Why Is My Unity VideoPlayer Not Playing Audio on Windows 10?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template