标签: avaudiosession

将AVCaptureDeviceInput添加到CaptureSession会重置/重新聚焦视频

录像应用程序.我希望它能够在不停止/暂停背景音乐的情况下工作(例如,当用户收听Apple Music时).这我可以设置类别做很好mixWithOthersAVAudioSession单.

设置类别后,我还需要添加AVCaptureDeviceInputAVCaptureSession(所以声音会被记录下来).这会导致背景音频的故障/打嗝以及视频重置/重新聚焦.

我已经调查过,似乎背景音频故障是无法避免的,但视频在添加输入时不应重置.视频重置的结果是录制视频的第一帧是暗/黑色,或者从失焦帧开始然后聚焦.

还检查Snapchat ios应用程序,他们在开始录制时也有音频故障,但视频开始顺利录制.我究竟做错了什么.

我的代码:

//Setting audio session to mixWithOthers upon startup
let session = AVAudioSession.sharedInstance()

do {
    try session.setCategory(AVAudioSessionCategoryPlayAndRecord,
                            with: [.mixWithOthers])
    if session.mode != AVAudioSessionModeVideoRecording {
        try session.setMode(AVAudioSessionModeVideoRecording)
    }
} catch let error {
    print("avsession category error: \(error)")
}
Run Code Online (Sandbox Code Playgroud)

然后:

//Just before recording starts will add audio input
let audioDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio)
do
{
    let deviceInput = try AVCaptureDeviceInput(device: audioDevice) as AVCaptureDeviceInput
    if captureSession.canAddInput(deviceInput) {
        captureSession.addInput(deviceInput)
    }
    else …
Run Code Online (Sandbox Code Playgroud)

ios avaudiosession swift

26
推荐指数
1
解决办法
631
查看次数

iOS检查应用程序是否可以访问麦克风

随着iOS 7的推出,应用程序必须在想要录制音频时请求麦克风访问.

如何检查应用程序是否可以访问麦克风?
在iOS 8 SDK中我可以使用AVAudioSessionRecordPermission枚举,但如何在iOS 7中检查?

信息:
我不想请求权限,我只想检查应用是否可以访问麦克风.(如位置访问权限):

if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
    // Do something
}
Run Code Online (Sandbox Code Playgroud)

microphone objective-c ios avaudiosession swift

24
推荐指数
6
解决办法
4万
查看次数

AVAudioSessionManager availableInputs"端口iPhone麦克风的未知选定数据源"

我已经在控制台日志中注意到这个错误了一段时间.虽然它不会影响我的应用程序的执行,但我发现它真的很烦人.因此,我开始追踪这个错误的来源.当我调用availableInputs时,结果证明了这一点

NSArray *inputs = [[AVAudioSession sharedInstance] availableInputs];
Run Code Online (Sandbox Code Playgroud)

它会给我日志消息:

ERROR:     [0x3d61318c] AVAudioSessionPortImpl.mm:50: ValidateRequiredFields: Unknown selected data source for Port iPhone Microphone (type: MicrophoneBuiltIn)
Run Code Online (Sandbox Code Playgroud)

我试图打印输入..

Printing description of inputs:
<__NSArrayI 0x188c4610>(
<AVAudioSessionPortDescription: 0x188c4580, type = MicrophoneBuiltIn; name = iPhone Microphone; UID = Built-In Microphone; selectedDataSource = (null)>,
<AVAudioSessionPortDescription: 0x18835d90, type = BluetoothHFP; name = Valore-BTi22; UID = 00:23:01:10:38:77-tsco; selectedDataSource = (null)>
Run Code Online (Sandbox Code Playgroud)

所以selectedDataSource是(null).我不知道该怎么办才能使它不为空?iPhone麦克风是一个内置输入......我想它已经由Apple设定了?

iphone ios avaudiosession

23
推荐指数
1
解决办法
2万
查看次数

与AVAudioSessionCategoryPlayAndRecord结合使用的低录音音量

当我设置:

[[AVAudioSession sharedInstance] setCategory:
    AVAudioSessionCategoryPlayAndRecord error:NULL];
Run Code Online (Sandbox Code Playgroud)

...录制和播放工作正常,只是播放音量比我在没有录制和设置PlayAndRecord时播放相同声音时低约60%.

因为我开始录制会话,我需要获得高音量峰值(以检查用户是否在麦克风中吹气).但是没有设置AVAudio..PlayandRecord,我不能在此期间播放任何声音.这就是我实现这个命令的原因.

任何帮助?

谢克斯

audio ios avaudiosession

21
推荐指数
4
解决办法
9637
查看次数

如何使MPMoviePlayerController忽略静音开关

我想播放一个视频,MPMoviePlayerController但我希望它忽略静音开关,类似于Youtube视频播放器的行为.

有任何想法吗?

iphone mpmovieplayercontroller ios avaudiosession

21
推荐指数
1
解决办法
7296
查看次数

iOS 13-WkWebView:在后台停止播放音频

我已经使用的应用程序WkWebView到从SoundCloud播放音频,iOS上的13测试版6音频停止时,应用程序是不是在前台,即使音频是在背景模式

开始播放时,将抛出以下断言:

Error acquiring assertion: <NSError: 0x282cf67c0; domain: RBSAssertionErrorDomain; code: 2; reason: "Required client entitlement is missing"> {
userInfo = {
    RBSAssertionAttribute = <RBSLegacyAttribute: 0x1592432e0; requestedReason: MediaPlayback; reason: MediaPlayback; flags: PreventTaskSuspend | PreventTaskThrottleDown | WantsForegroundResourcePriority>;
} 
Run Code Online (Sandbox Code Playgroud)

进入后台状态后,将引发以下声明并暂停音频:

Can't end BackgroundTask: no background task exists with identifier 13 (0xd), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug. 
[ProcessSuspension] Background task expired while holding WebKit ProcessAssertion (isMainThread? 1).
Run Code Online (Sandbox Code Playgroud)

这在iOS 12中不会发生,在iOS 12中,音频在后台正常播放。

avaudiosession swift wkwebview ios-background-mode ios13

20
推荐指数
1
解决办法
1528
查看次数

AVSpeechSynthesizer错误AudioSession

我正在玩AVSpeechSynthesizer并且总是遇到这些错误:

ERROR:     >aqsrv> 65: Exception caught in (null) - error -66634
ERROR:     AVAudioSessionUtilities.h:88: GetProperty_DefaultToZero: AudioSessionGetProperty ('disa') failed with error: '?ytp'
Run Code Online (Sandbox Code Playgroud)

我的代码是:

AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
[synthesizer setDelegate:self];
speechSpeed = AVSpeechUtteranceMinimumSpeechRate;
AVSpeechUtterance *synUtt = [[AVSpeechUtterance alloc] initWithString:[[self text] text]];
[synUtt setRate:speechSpeed];
[synUtt setVoice:[AVSpeechSynthesisVoice voiceWithLanguage:languageCode]];
[synthesizer speakUtterance:synUtt];
Run Code Online (Sandbox Code Playgroud)

有谁知道如何解决这些错误?

objective-c avfoundation ios avaudiosession

19
推荐指数
1
解决办法
8175
查看次数

iOS AVAudioSession中断通知无法按预期工作

我想知道我何时AVAudioRecorder无法进入(例如音乐开始播放时).

正如audioRecorderEndInterruption将在iOS 9中弃用的那样,我专注于AVAudioSession中断通知(但两者都没有按预期工作).

问题是,如果应用程序在中断发生时仍然在前台,则永远不会调用中断通知.

例如:用户启动和停止播放音乐而不将应用程序移动到后台.

要检测我正在使用的任何中断:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioSessionWasInterrupted:) name:AVAudioSessionInterruptionNotification object:nil];
...
- (void)audioSessionWasInterrupted:(NSNotification *)notification {
    if ([notification.name isEqualToString:AVAudioSessionInterruptionNotification]) {
        NSLog(@"Interruption notification");

        if ([[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey] isEqualToNumber:[NSNumber numberWithInt:AVAudioSessionInterruptionTypeBegan]]) {
            NSLog(@"InterruptionTypeBegan");
        } else {
            NSLog(@"InterruptionTypeEnded");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

InterruptionTypeBegan按预期得到了,但InterruptionTypeEnded如果应用程序仍在前台,则不会被调用(意味着在将应用程序放置在后台并返回到前台之前不会调用它).

InterruptionTypeEnded当应用程序在前台时发生中断时,我如何收到通知?

interrupt avfoundation avaudiorecorder ios avaudiosession

18
推荐指数
1
解决办法
1万
查看次数

IOS:AVAudioSession无法正常工作

我试图使用AVAudioSession,但它抛出了这个运行时错误: [avas] AVAudioSessionPortImpl.mm:56:ValidateRequiredFields:Unknown selected data source for Port Speaker (type Speaker).如果它有助于我只是记录音频,并监控当前的分贝.我将类别设置为AVAudioSessionCategoryRecord,并将模式设置为AVAudioSessionModeMeasurement.这是代码:

class ViewController: UIViewController {

    let captureSession = AVCaptureSession()
    var recording = false;
    var ready = false;

    let audioSession = AVAudioSession.sharedInstance()

    @IBOutlet public weak var dBLabel: UILabel!

    func alert(title: String, message: String = "", handler: ((UIAlertAction) -> Swift.Void)? = nil) -> Void {
        var usedMessage: String
        if(message.characters.count < 1) {
            usedMessage = title;
        } else {
            usedMessage = message;
        }
        let alert = UIAlertController(title: title, …
Run Code Online (Sandbox Code Playgroud)

avfoundation ios avaudiosession swift

18
推荐指数
1
解决办法
8540
查看次数

替代已弃用的AudioSessionGetProperty,适用于iOS 7

我正在使用AudioSessionGetProperty来检查'audioIsAlreadyPlaying'.Xcode表示: 'AudioSessionGetProperty'已被弃用:首先在iOS 7.0中弃用

请有人告诉我应该使用什么来获取audioIsAlreadyPlaying属性.

AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying,
                        &propertySize,
                        &audioIsAlreadyPlaying);
return audioIsAlreadyPlaying;
Run Code Online (Sandbox Code Playgroud)

ios avaudiosession

17
推荐指数
1
解决办法
1万
查看次数