开发者

Seek functionality not working in AVAudioPlayer in iPhone App?

开发者 https://www.devze.com 2023-04-06 00:31 出处:网络
I am using below code for that but when I slide the slider it is calling updateTime method but stuck at player.currentTime and not playing further

I am using below code for that but when I slide the slider it is calling updateTime method but stuck at player.currentTime and not playing further

On single sliding of slider it ge开发者_运维知识库ts stuck

-(IBAction)slide
{
    [player setCurrentTime:slider.value];
    //NSLog(@"slider value in slide : %f",[slider value]);

}

    -(void) updateTime:(NSTimer *)timer
    {
        slider.value = player.currentTime;
        //NSLog(@"player current time in update time : %f",[player currentTime]);
       }

    - (IBAction)play:(id)sender {

        NSError *error;
        NSURL *url  = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Sing_for_me.mp3" ofType:nil]];
        player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
        if(!player) NSLog(@"Error : %@",&error);
        [player prepareToPlay];
        slider.continuous=YES;

        slider.maximumValue = [player duration];
        //NSLog(@"player duration : %f",[player duration]);
       // NSLog(@"slider duration : %f",slider.value);
        //NSLog(@"player current time : %f",[player currentTime]);
        slider.value=0.0;

        [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
        [player play];
    }

what could be wrong?

0

精彩评论

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