AVAudioPlayer via Speakers

后端 未结 8 644
甜味超标
甜味超标 2021-02-06 13:16

I got the following code:

- (id)init {
    if (self = [super init]) {
        UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
        AudioSessionS         


        
相关标签:
8条回答
  • 2021-02-06 13:58

    I used the AudioToolbox framework that's why I initialized my audio session as following:

    AudioSessionInitialize(NULL, NULL, NULL, NULL);
    

    Here's the rest of my code that I used to configure the audio session. I didn't override the audio route and I also think this is not necessary.

    UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
    OSStatus err = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory,
                                           sizeof(sessionCategory),
                                           &sessionCategory);
    AudioSessionSetActive(TRUE);
    if (err) {
        NSLog(@"AudioSessionSetProperty kAudioSessionProperty_AudioCategory failed: %d", err);
    }
    
    0 讨论(0)
  • 2021-02-06 14:02

    I'm just going to clarify this for other readers of this post.

    I was looking for the answer to this problem, specifically for the SpeakHere example. I grabbed this little chunk of code and it did the trick.

     UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
        AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
    

    I hope this is not too much of a digression. I just thought it would be good for those who just need these two little statements.

    0 讨论(0)
提交回复
热议问题