2011-09-06 48 views
0

m製作需要播放錄製音頻文件的應用程序。 對於具有sound.h/.m文件和setting.h/.m文件的那個m在聲音中,我有一個方法 - 更新播放器,它將在創建新錄製文件時更新我的​​音頻播放器。如下所示。 。AVAudioPlayer..its playing old

-(AVAudioPlayer *)updatePlayer 
{ 
    if (!mAudioPlayer) 
    { 
    self.mAudioPlayer = [[[AVAudioPlayer alloc]initWithContentsOfURL:mURLObj error:nil]autorelease]; 
    } 
    return mAudioPlayer; 
} 

現在,每當在settingcontroller..as創建一個新錄製的音頻文件時mcalling這梅託德如下..

-(void)hasNewRecorded:(BOOL)inFlag 
{ 
    if (inFlag == YES) 
    { 
     mRecorder.mAudioPlayer = [[mRecorder updatePlayer]retain]; 
    } 
    [mRecorder.mAudioPlayer release]; 
} 

我知道,在做錯誤的somewhere..But couldnot能解決最近2天的問題。我期待着您的幫助。

回答

0

你正在發起只有當不存在這裏了新的音頻播放器,

if (!mAudioPlayer) 
    { 
    self.mAudioPlayer = [[[AVAudioPlayer alloc]initWithContentsOfURL:mURLObj error:nil]autorelease]; 
    } 

作爲一名球員已經存在一個新的玩家不會被分配。所以舊的音頻文件將繼續播放。嘗試在此for循環中修復斷點並檢查,如果這是問題,請更改條件 - 釋放舊音頻播放器並分配新音頻。

+0

是的,據我所知,但每當我嘗試釋放舊的玩家時,就沒有玩家玩了。爲什麼在分配這個之前,我把它設置爲nil ... self.mAudioPlayer = nil if(!mAudioPlayer) self.mAudioPlayer = [[[AVAudioPlayer alloc] initWithContentsOfURL:mURLObj error:nil] autorelease] ; }這是一個錯誤的方式? – iCoder4777

+0

是的。您將該值設爲零,並檢查是否執行無法執行的條件代碼。你在這裏看到問題嗎? – sElanthiraiyan