开发者

How to pause and resume same song in iPhone sdk using AVAudioPlayer

I want to pause the song and continue from that point of duration in iphone using programmatic-ally. When I tried to pause the song and again I want to start to play the song where I paused. How开发者_运维知识库 it can be coded. Is there any direct properties or suggest any code to that may solve my problem.

-(void)playMusic
{
    path=[[NSBundle mainBundle]pathForResource:@"01my song here" ofType:@"mp3"];
    AVAudioPlayer *myAudio=[[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:path ] error:nil];
    self.audioPlayer=myAudio;
    [myAudio release];
    //audioPlayer.playing ;
    [audioPlayer play];
}

-(void)stopMusic
{
    [audioPlayer stop];
}
-(void)pauseMusic
{
    [audioPlayer pause];// here it is just stopping, how can I start where I sttoped.
}

Thank you, Madan Mohan.


if(!player){


    NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
    resourcePath = [resourcePath stringByAppendingString:@"/grabbag.m4a"];
    NSLog(@"Path to play: %@", resourcePath);
    NSError* err;

    //Initialize our player pointing to the path to our resource
    player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath] error:&err];

    if( err ){
        //bail!
        NSLog(@"Failed with reason: %@", [err localizedDescription]);
    }
    else{
        //set our delegate, flip the button and let the magic happen
        player.delegate = self;
        [self flipButton:YES];
        [player play];
    }
}
else{
    //If the player exists here, then we're already playing.
    NSLog(@"Resuming playback!");
    [player play];
    [self flipButton:YES];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜