【问题标题】:iPhone Allow Other App to Play Audio While Recording Audio / ShazamiPhone 允许其他应用程序在录制音频/Shazam 时播放音频
【发布时间】:2012-05-11 16:15:17
【问题描述】:

希望做 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 的工作原理而言,我确实发现设置有所不同,但在所有情况下,当我的应用获取麦克风时,它都会停止来自其他应用的音频。

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

【问题讨论】:

    标签: iphone audio-recording audio-player shazam


    【解决方案1】:

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

    仅供参考,这是使用 AudioQueue 接口

    所以我们...

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

    • AudioQueueNewInput
    • AudioQueueAddPropertyListener
    • AudioQueueAllocateBuffer(s)
    • AudioQueueEnqueueBuffer(s)
    • setupCat
    • 设置鸭
    • 设置音频路由
    • 设置混合
    • 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
            {}
    }
    

    【讨论】:

    • 您还必须确保将音频路由设置为最后/当前的音频路由...如何采用最后/当前的路由?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多