开发者

AVAudioPlayer..its playing old one

m making an app which requires to play recorded audio files. For that m having a sound.h/.m file and setting.h/.m file In sound I have a method - update player which will update my audio-player if a new recorded files has been created.as follows..

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

Now , mcalling this metod every time when a new recorded audio file is created in settingcontroller..as follows..

-(void)hasNewRecorded:(BOOL)inFlag
{
    if (inFlag == YES)
  开发者_运维技巧  {
        mRecorder.mAudioPlayer = [[mRecorder updatePlayer]retain];
    }
    [mRecorder.mAudioPlayer release];
}

I know that m doing wrong somewhere..But couldnot able to fix the problem for last 2 days. I'm looking forward for your help.


You are initiating a new audio player only if doesn't exists here,

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

A new player wont be allocated as a player exists already. So the old audio file will keep playing. Try fixing a breakpoint inside this for loop and check, If that's the problem change the condition - release the old audio player and allocate new one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜