2 developerwab developerWab 于 2013.01.11 11:05 提问

AVAudioPlayer搜索功能不好用

我用下面实现代码时,滑动滚动条后调用updateTime方法,但是程序卡在了player.currentTime,不再往下运行了。

-(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];
    }

1个回答

wangyaninglm
wangyaninglm   Ds   Rxr 2015.01.13 22:28

你可以参考一下这个帖子的解决办法:
http://bbs.csdn.net/topics/390491178

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!