如何在扬声器上播放音频而不是耳机更弱? [英] How to play audio over speakers rather than the much weaker ear speakers?

查看:144
本文介绍了如何在扬声器上播放音频而不是耳机更弱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习核心音频。出于某种原因,处理图表的声音仅通过弱耳机(当您将设备放在耳边时)而不是通过iPhone的常规扬声器播放。

I'm learning core audio. For some reason the sound of the processing graph only plays through the weak "ear speakers" (when you hold device to your ear) but not over the regular speakers of the iPhone.

这是设置音频会话的代码,但我无法看到它配置音频路由的位置:

This is the code which sets up the audio session but I can't see where it configures the audio route:

- (void) setupAudioSession {

    AVAudioSession *mySession = [AVAudioSession sharedInstance];

    // Specify that this object is the delegate of the audio session, so that
    //    this object's endInterruption method will be invoked when needed.
    [mySession setDelegate: self];

    // Assign the Playback category to the audio session.
    NSError *audioSessionError = nil;
    [mySession setCategory: AVAudioSessionCategoryPlayAndRecord//AVAudioSessionCategoryPlayback
                     error: &audioSessionError];

    if (audioSessionError != nil) {

        NSLog (@"Error setting audio session category.");
        return;
    }

    // Request the desired hardware sample rate.
    self.graphSampleRate = 44100.0;    // Hertz

    [mySession setPreferredHardwareSampleRate: graphSampleRate
                                        error: &audioSessionError];

    if (audioSessionError != nil) {

        NSLog (@"Error setting preferred hardware sample rate.");
        return;
    }

    // Activate the audio session
    [mySession setActive: YES
                   error: &audioSessionError];

    if (audioSessionError != nil) {

        NSLog (@"Error activating audio session during initial setup.");
        return;
    }

    // Obtain the actual hardware sample rate and store it for later use in the audio processing graph.
    self.graphSampleRate = [mySession currentHardwareSampleRate];

    // Register the audio route change listener callback function with the audio session.
    AudioSessionAddPropertyListener (
        kAudioSessionProperty_AudioRouteChange,
        audioRouteChangeListenerCallback,
        self
    );
}

在核心音频的哪个位置你说播放扬声器音频单元的声音?

At which point in core audio do you say "play over speakers" when playing sounds with audio units?

推荐答案

您可以使用 setCategory withOption:

[mySession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:&audioSessionError];

这篇关于如何在扬声器上播放音频而不是耳机更弱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆