简体   繁体   English

Unity Microphone.End() 将 iOS 上的所有游戏音频静音

[英]Unity Microphone.End() mutes all game audio on iOS

This happens if iPhone silent mode is on.如果 iPhone 静音模式打开,就会发生这种情况。 I have a button that records the microphone in the game.我有一个在游戏中记录麦克风的按钮。 When the game starts background music and SFX play just fine.当游戏开始时,背景音乐和 SFX 播放得很好。 When I stop recording, all game audio is muted until I turn iPhone silent mode off.当我停止录制时,所有游戏音频都会静音,直到我关闭 iPhone 静音模式。 There is no problem if silent mode was off to begin with.如果一开始就关闭静音模式,则没有问题。

EDIT TO INCLUDE CODE:编辑以包含代码:

public void RecordAudio()
{
    recordedClip = Microphone.Start(null, false, 20, 44100);
}

//the audio gets muted when I run this. //当我运行它时,音频被静音。

public void StopRecordingAudio()
{

    tempPath = Path.Combine(Application.persistentDataPath, "Audio");
    tempPath = Path.Combine(tempPath, "audio_clip.wav");
    Microphone.End(null);
    SaveWav.Save(tempPath, recordedClip);

}

I am using this to save the audio clip.我正在使用来保存音频剪辑。

The solution is to check Prepare iOS For Recording and Force iOS Speakers Speakers When Recording in Player Settings/iOS.解决方案是在播放器设置/iOS 中检查准备 iOS 进行录制和强制 iOS 扬声器扬声器。

Checking Prepare iOS For Recording caused a different error where the microphone failed to initialize.选中为录制准备 iOS 会导致麦克风无法初始化的另一个错误。 This is fixed by adding the following to UnityViewControllerBase.mm in the Xcode Project/Classes/UI in (void)viewWillAppear ;通过在(void)viewWillAppear的 Xcode Project/Classes/UI 中将以下内容添加到 UnityViewControllerBase.mm 来解决此问题;

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
         [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
         [audioSession setActive:YES error:nil];

Don't forget: #import "AVFoundation/AVFoundation.h"不要忘记: #import "AVFoundation/AVFoundation.h"

Theres also a bug I'm Unity that forces audio to play from the earpiece even if you check Force Speakers when Recording.还有一个错误,我是 Unity,即使您在录制时选中强制扬声器,也会强制从听筒播放音频。 This only happens when you check Prepare iOS For Recording.仅当您选中准备 iOS 以进行录制时才会发生这种情况。 The issue can be tracked here I used this as a temporary fix for that even though it's quite old but works - in the meantime as Unity fixes the bug.可以在此处跟踪该问题我将用作临时修复程序,即使它已经很旧但可以工作 - 同时 Unity 修复了该错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM