iPhone 允许其他应用在录制音频/Shazam 时播放音频 [英] iPhone Allow Other App to Play Audio While Recording Audio / Shazam

查看:34
本文介绍了iPhone 允许其他应用在录制音频/Shazam 时播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在另一个应用程序正在播放音频的同时录制音频,这与 Shazam 所做的差不多.

Looking to do pretty much what Shazam is doing as far as recording audio while another app is playing audio.

1) 录音很好,没问题

1) Recording audio fine, no problem here

2) 当应用启动并开始录音时,来自另一个应用(iTunes 等)的音乐停止.

2) When app starts and starts recording, the music from another app stops (itunes, etc).

3) 我玩过 AV 音频设置的所有咒语,但没有成功让音频继续/恢复.

3) I have played with all of the incantations of the AV Audio settings with no luck in having the audio continue / resume.

4) 当 Shazam 启动时,音频停止一会儿,然后恢复.我假设 Shazam 正在做一些事情来重新启动音乐播放器的音频?我搜索并找不到是否有办法做到这一点.

4) When Shazam starts, the audio stop for a bit, and then resumes. I assume that Shazam is doing something to restart the audio with the music player? I searched and could not find if there is a way to do this.

因此,如果有人有适当的设置来使其正常工作,我们将不胜感激.

So if anyone has the proper settings to get this to work, it would be appreciated.

另外,说,请阅读 AV 文档,这不是答案,我没有运气看过这些.

Also, Saying, please read the AV docs, is not an answer, I have looked these over with no luck.

我试过在这里找到

http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionCategories/AudioSessionCategories.html

尝试了 AV 和 K 类型的设置.就 MIC 的确切工作方式而言,我确实看到设置有所不同,但在所有情况下,当我的应用获取麦克风时,它会停止来自其他应用的音频.

Have tried both the AV and K type of settings. I do see a difference in the settings as far as how exactly the MIC works, but in all cases when my app gets the mic, it stops the audio from the other app.

如果我必须牺牲一只站在苹果方向的鸡,这很好,让我知道是什么类型的鸡:-)

If I have to sacrifice a chicken standing in the direction of Apple, this is fine, just let me know what type of chicken :-)

推荐答案

经过一番折腾,看来使用 MixWithOthers 才是关键.您还必须确保将音频路由设置为最后/当前的音频路由...

After some back and forth, it looks like using the MixWithOthers is the key. You have to also make sure that the audio route is set to the last / current audio route...

仅供参考,这是带有 AudioQueue 接口的

FYI This is with the AudioQueue interface

所以我们...

/用 iPod 开始音乐/启动我们的应用程序

/ Start Music with iPod / Start our app with

  • AudioQueueNewInput
  • AudioQueueAddPropertyListener
  • AudioQueueAllocateBuffer(s)
  • AudioQueueEnqueueBuffer(s)
  • setupCat
  • setupDuck
  • setupAudioRoute
  • 设置混合
  • AudioSessionSetActive (true)
  • AudioQueueStart
typedef union 
{
    OSStatus propertyResult;
    char a[4];
} unionstatus;

unionstatus u2;

typedef union 
{
    UInt32 UI32sessionCat;
    char a[4];
} unionuint32;

unionuint32 usc2;

bool setAudioUInt32 ( UInt32 property, UInt32 value )
{
    bool result = true;

    UInt32 UI32 = value;
    UInt32 UI32size = sizeof(UI32);

    u2.propertyResult = AudioSessionSetProperty (property, UI32size , &UI32 );

    if ( u2.propertyResult )
    {
        printf("Error Set %ld %lx %c%c%c%c
",u2.propertyResult,u2.propertyResult,u2.a[3],u2.a[2],u2.a[1],u2.a[0]);
        result = false;
    }
    return result;
}

UInt32 getAudioSettingInt ( UInt32 value )
{
    UInt32  I32;
    UInt32  I32size = sizeof(I32);

    u2.propertyResult = AudioSessionGetProperty ( value , &I32size, &I32 );

    if ( u2.propertyResult )
        printf("Error Get %ld %lx %c%c%c%c
",u2.propertyResult,u2.propertyResult,u2.a[3],u2.a[2],u2.a[1],u2.a[0]);

    return (I32);
}

<小时>

/// checking taken out

bool otherPlaying = getAudioSettingInt ( kAudioSessionProperty_OtherAudioIsPlaying );
if ( otherPlaying )
{
    setAudioUInt32 (kAudioSessionProperty_OtherMixableAudioShouldDuck, false);
    // this returns a string, arg, have to look for string values, etc.
    UInt32 audioRoute = getAudioSettingInt ( kAudioSessionProperty_AudioRoute );

    CFStringRef ar = (CFStringRef) audioRoute;
    CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
    const char *car = CFStringGetCStringPtr(ar,encodingMethod);
    CFRange range = CFStringFind(ar,CFSTR("Headphones"),kCFCompareCaseInsensitive);

    if ( range.length == 0 ) // we have speakers
        result = setAudioUInt32 (kAudioSessionProperty_OverrideAudioRoute, kAudioSessionOverrideAudioRoute_Speaker);
    else // we have headphones
        {}
}

这篇关于iPhone 允许其他应用在录制音频/Shazam 时播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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