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

后端 未结 1 1757
庸人自扰
庸人自扰 2021-01-03 09:25

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 son

相关标签:
1条回答
  • 2021-01-03 10:05
    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 讨论(0)
提交回复
热议问题