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

查看:438
本文介绍了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)当应用开始并开始录制时,来自另一个应用的音乐停止(音调等).

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
  • setupMixing
  • AudioSessionSetActive(true)
  • AudioQueueStart
  • AudioQueueNewInput
  • AudioQueueAddPropertyListener
  • AudioQueueAllocateBuffer(s)
  • AudioQueueEnqueueBuffer(s)
  • setupCat
  • setupDuck
  • setupAudioRoute
  • setupMixing
  • 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\n",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\n",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天全站免登陆