设置
我目前正在开发一个音乐应用程序,但进度条滑块出现问题。
self.musicPlayer
是个[MPMusicPlayerController applicationMusicPlayer]
self.currentlyPlayingTotalDuration
是一个NSNumber
self.currentlyPlayingTimeSlider
是一个UISlider
概述
当在MPMusicPlayerController
. 在这种方法中(未显示全部),我将我的音乐播放器设置为播放挑选的歌曲(工作)并播放它(工作)。然后我将歌曲的总持续时间设置为滑块的最大值(工作)
self.currentlyPlayingTotalDuration = [[NSNumber alloc] initWithFloat:(int)[NSValue valueWithPointer:[self.musicPlayer.nowPlayingItem valueForKey:MPMediaItemPropertyPlaybackDuration]]];
[self.currentlyPlayingTimeSlider setMaximumValue:self.currentlyPlayingTotalDuration.floatValue];
我已经记录了这些值以查看这些值是否设置正确(它们是)
NSLog(@"Number:%@", [NSNumber numberWithFloat:(int)[NSValue valueWithPointer:[self.musicPlayer.nowPlayingItem valueForKey:MPMediaItemPropertyPlaybackDuration]]]);
NSLog(@"Max:%f", self.currentlyPlayingTimeSlider.maximumValue);
日志输出如下,看起来应该
2011-08-24 13:38:25.004 App [1241:707] Number:1107392
2011-08-24 13:38:25.009 App [1241:707] Max:1400544.000000
然后我将我的currentlyPlayingTimeSlider
值设置为 0 开始(工作)
self.currentlyPlayingTimeSlider.value = 0.0;
接下来,我将我的updateSliderTime
方法设置为每秒调用一次以将进度条进一步移动一秒(工作)
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateSliderTime:) userInfo:nil repeats:YES];
问题
该方法的完整方法代码如下,即使它每秒被调用一次updateSliderTime
,它也不起作用
- (void)updateSliderTime:(NSTimer *)timer {
[self.currentlyPlayingTimeSlider setValue:[[NSNumber numberWithDouble:self.musicPlayer.currentPlaybackTime] floatValue]];
}
valueChanged
此外,我在 Interface Builder 中设置的事件调用的方法如下。它也不起作用
- (IBAction)sliderChanged:(id)sender {
[self.musicPlayer setCurrentPlaybackTime:[[NSNumber numberWithFloat:self.currentlyPlayingTimeSlider.value] doubleValue]];
}
谁能帮我弄清楚我做错了什么?它必须在最后两种方法中有所体现,因为第一种方法很好。我在其他任何地方都没有对滑块进行其他自定义/弄乱。