PDA

View Full Version : AVAudioPLayer pause method




RashiMahajan
Apr 17, 2009, 02:35 AM
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:@"xyz" ofType:@"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..



hemalimojidra
Apr 20, 2009, 06:21 AM
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:@"xyz" ofType:@"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..

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