2012-05-11 156 views
3

只需在另一个应用程序播放音频时录制音频,就可以做很多Shazam的工作。iPhone允许其他应用程序在录制音频时播放音频/ Shazam

1)录制音频细,这里

2)当应用程序启动并开始录制,从另一个应用程序的音乐停止(iTunes中没有问题,等等)。

3)我已经玩过所有的AV音频设置的咒语,没有运气让音频继续/恢复。

4)当Shazam启动时,音频停止一会儿,然后继续。我认为Shazam正在用音乐播放器重新开始音频?我搜索并找不到是否有办法做到这一点。

所以,如果任何人有适当的设置,让这个工作,它将不胜感激。

另外,说,请阅读AV文件,不是一个答案,我已经看过这些没有运气。

我试图在这里找到

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

试过AV和K型的设置都。就MIC的工作原理而言,我确实发现设置有所不同,但在所有情况下,当我的应用程序获得麦克风时,它会停止来自其他应用程序的音频。

如果我不得不牺牲在苹果的方向鸡站立,这是好的,只是让我知道什么类型的鸡:-)

回答

1

后一些来回,它看起来像使用MixWithOthers是钥匙。你也必须确保音频路由设置为最后/当前音频路由...

FYI这是与AudioQueue接口

所以我们...

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

  • AudioQueueNewInput
  • AudioQueueAddPropertyListener
  • AudioQueueAllocateBuffer(S)
  • AudioQueueEnqueueBuffer(S)
  • setupCat
  • setupDuck
  • setupAudioRoute
  • setupMixing
  • AudioSessionSetActive(真)
  • 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 
     {} 
} 
+0

你也必须确保音频路由设置为最后/目前的音频路线...如何获取最新/当前路线? – loretoparisi