2010-07-10 62 views
1

我在創建必須播放的應用程序中使用SpeakHere音頻類&同時記錄。SpeakHere的AudioQueue代碼在iPad上失敗

我在通用應用程序構建中使用帶有3.2設備目標的最新SDK(目標爲iPad & iPhone)。

該應用程序使用MPMoviePlayerController播放流式電影並同時錄製音頻。

這在iPhone上100%完美。

但是,它在我的客戶iPad上100%失敗。日誌顯示!AudioSession只是拒絕活動的錯誤!我從他那裏收到的每個日誌文件都包含衆多的中斷&路由變更(即類別)被返回給回調函數。 **在iPhone上我根本看不到任何這樣的東西。日誌只顯示記錄是創建的,並記錄到指定的文件。沒有中斷,沒有路線變化,沒有廢話。

這裏的相關日誌:

Jul 10 07:15:21 iPad mediaserverd[15502] <Error>: [07:15:21.464 <0x1207000>] AudioSessionSetClientPlayState: Error adding running client - session not active 
Sat Jul 10 07:15:21 iPad mediaserverd[15502] <Error>: [07:15:21.464 <AudioQueueServer>] AudioQueue: Error '!act' from AudioSessionSetClientPlayState(15642) 

我掐滅我的兩個回調函數僅僅記錄中斷和路由變化(有原因)的發生。所以我不會打擾發佈代碼,因爲它沒有字面意思。我曾多次在iPad上看到這些日誌,但一次嘗試在iPad上開始錄製。

我已經閱讀了幾乎所有可以在Apple Dev論壇和StackOverflow中找到的帖子,但似乎無法找到具有相同問題或Apple文檔中解釋iPad行爲差異的相關筆記的人。 - 注意:iPad確實顯示了一些其他已修復的缺陷行爲,例如不匹配的Begin Interruption調用永不結束(所以我從不停用會話)。

我從來沒有收到任何日誌,指出從AudioQueue或AudioSession代碼中的任何失敗的初始化或激活調用。當我嘗試開始錄製時,它會失敗。 - 我甚至試圖強制AudioSessionSetActive(true);在每次嘗試使用音響系統之前都會打電話,但我仍然收到這些錯誤。

下面是初始化調用的相關代碼:

//Initialize the Sound System 
    OSStatus error = AudioSessionInitialize(NULL, NULL, interruptionListener, self); 
    if (error){ printf("ERROR INITIALIZING AUDIO SESSION! %d\n", (int)error); } 
    else { 
     //must set the session active first according to devs talking about some defect....   
     error = AudioSessionSetActive(true); 
     if (error) NSLog(@"AudioSessionSetActive (true) failed"); 

     UInt32 category = kAudioSessionCategory_PlayAndRecord; 
     error = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category); 
     if (error) printf("couldn't set audio category!\n"); 

     error = AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, propListener, self); 
     if (error) printf("ERROR ADDING AUDIO SESSION PROP LISTENER! %d\n", (int)error); 

     //Force mixing! 
     UInt32 allowMixing = true; 
     error = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (allowMixing), &allowMixing); 
     if (error) printf("ERROR ENABLING MIXING PROPS! %d\n", (int)error); 

     UInt32 inputAvailable = 0; 
     UInt32 size = sizeof(inputAvailable);   
     // we do not want to allow recording if input is not available 
     error = AudioSessionGetProperty(kAudioSessionProperty_AudioInputAvailable, &size, &inputAvailable); 
     if (error) printf("ERROR GETTING INPUT AVAILABILITY! %d\n", (int)error); 
     isInputAvailable = (inputAvailable) ? YES : NO; 


     //iPad doesn't require the routing changes, branched to help isolate iPad behavioral issues 
     if(! [Utils GetMainVC].usingiPad){ 
      //redirect to speaker? //this only resets on a category change! 
      UInt32 doChangeDefaultRoute = 1;   
      error = AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute); 
      if (error) printf("ERROR CHANGING DEFAULT ROUTE PROPS! %d\n", (int)error); 

      //this resets with interruption and/or route changes 
      UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; 
      error = AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride); 
      if (error) printf("ERROR SPEAKER ROUTE PROPS! %d\n", (int)error); 
     } 

     // we also need to listen to see if input availability changes 
     error = AudioSessionAddPropertyListener(kAudioSessionProperty_AudioInputAvailable, propListener, self); 
     if (error) printf("ERROR ADDING AUDIO SESSION PROP LISTENER! %d\n", (int)error); 

     error = AudioSessionSetActive(true); 
     if (error) NSLog(@"AudioSessionSetActive (true) failed"); 
    } 

    // Allocate our singleton instance for the recorder & player object 
    myRecorder = new AQRecorder(); 
    myPlayer = new AQPlayer(); 

後來在LoadState的回調視頻我只是嘗試啓動記錄到預定的文件路徑:

myRecorder->StartRecord((CFStringRef)myPathStr); 

錄音完全失敗。

感謝您的時間和幫助。

回答

0

原來這是一個奇怪的問題。

1)只使用錄音和回放,代碼在iPad上完美運行。

2)添加電影播放,不要調用任何路由更改,並在iPad上正常工作。

以某種方式,Movie Player播放的存在足以以某種方式更改AudioSession,從而強制更改任何路由(如使用設備揚聲器而不是耳機),導致AudioSession變爲非活動狀態。