收藏
回答

Unity的VideoPlayer组件能播放视频但是真机上无法静音,该如何解决?

微信版本8.0.71

以下是初始化videoPlayer代码

// 配置 VideoPlayer
videoPlayer.skipOnDrop = false; // 不丢弃帧,保证流畅
videoPlayer.aspectRatio = VideoAspectRatio.FitInside; // 保持比例

// 使用 AudioSource 模式输出音频
videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;

// 创建或获取 AudioSource
if (videoAudioSource == null)
{
    videoAudioSource = gameObject.GetComponent<AudioSource>();
    if (videoAudioSource == null)
    {
        videoAudioSource = gameObject.AddComponent<AudioSource>();
    }
}
videoAudioSource.playOnAwake = false;
videoAudioSource.mute = isMute;

// 绑定 AudioSource 到 VideoPlayer 音轨 0
videoPlayer.SetTargetAudioSource(0, videoAudioSource);

videoPlayer.playOnAwake = false;
videoPlayer.waitForFirstFrame = true;
videoPlayer.loopPointReached += OnVideoFinished;
videoPlayer.errorReceived += OnVideoError;
videoPlayer.prepareCompleted += OnVideoPrepared;


回答关注问题邀请回答
收藏
登录 后发表内容