AVAudioPLayer pause method

Discussion in 'iOS Programming' started by RashiMahajan, Apr 17, 2009.

  1. macrumors newbie

    Joined:
    Apr 17, 2009
    #1
    HI,
    M using AVAudioPalyer to play my mp3 file..
    t is working fine. but when call pause method to pause the pm,3 file , its dont respond/stops, it continue to play.. evn it dont response to stop...
    wht shld i do or wht m skipping..???
    Here posting the code to for the clarity purpose

    if(...)
    {
    NSString *newAudioFile = [[NSBundle mainBundle] pathForResource:mad:"xyz" ofType:mad:"mp3"];
    AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:newAudioFile] error:NULL];
    [audioPlayer setDelegate:self];
    [audioPlayer prepareToPlay];
    [audioPlayer play];


    if(..){
    [audioPlayer pause];
    }

    Its not working fore Pause......
    Wht m skipping..
     
  2. macrumors newbie

    Joined:
    Nov 7, 2008
    #2
    Make audioPlayer object as a class object than do this..
    Like...
    in .h file
    @interface AudioPlayerView : UIView <AVAudioPlayerDelegate>{
    AVAudioPlayer *audioPlayer;
    }
    @property (nonatomic, retain) AVAudioPlayer *audioPlayer;
    @end

    in .m file

    @synthesize audioPlayer;

    -(init){
    AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileUrl error: nil];
    self.audioPlayer = newPlayer;
    [newPlayer release];
    [self.audioPlayer setDelegate: self];

    }

    -(void) play{
    [self.audioPlayer play];
    }

    -(void) pause{
    [self.audioPlayer pause];
    }


    -(void) stop{
    [self.audioPlayer stop];
    }


    I am success using this coding... Try it

    Thanks
    Hemali mojidra
     

Share This Page