Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用AVAudioPlayer的当前时间控制幻灯片放映_Objective C_Ios4_Avaudioplayer - Fatal编程技术网

Objective c 使用AVAudioPlayer的当前时间控制幻灯片放映

Objective c 使用AVAudioPlayer的当前时间控制幻灯片放映,objective-c,ios4,avaudioplayer,Objective C,Ios4,Avaudioplayer,我使用AVAudioPlayer播放MP3文件。当播放器运行时,我想用播放器的当前时间控制幻灯片播放。当然,我可以用一个NSTimer来实现这一点,它会在游戏开始时启动,但这听起来并不是一个好的解决方案。我如何让观察者看到AVAudioPlayer的当前时间值 谢谢, Philip最干净的方法是自己使用AVPlayer设置音频播放器,并使用设置时间观察 如果您一直使用AVAudioPlayer,我相信您可以使用它来监听当前时间的变化: static NSString *someObservat

我使用AVAudioPlayer播放MP3文件。当播放器运行时,我想用播放器的当前时间控制幻灯片播放。当然,我可以用一个NSTimer来实现这一点,它会在游戏开始时启动,但这听起来并不是一个好的解决方案。我如何让观察者看到AVAudioPlayer的当前时间值

谢谢,
Philip

最干净的方法是自己使用
AVPlayer
设置音频播放器,并使用设置时间观察


如果您一直使用AVAudioPlayer,我相信您可以使用它来监听当前时间的变化:

static NSString *someObservationContext = @"something";

[audioPlayer addObserver:self forKeyPath:@"currentTime" options:0 context:&someObservationContext];
然后实施

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if (context == &someObservationContext) {
        NSTimeInterval t = [(AVAudioPlayer *)object currentTime];
        // do your thing
    } else {
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }

在拆除AVAudioPlayer之前,请务必调用
-[NSObject removeObserver:forKeyPath:][/code>移除观察挂钩。

最干净的方法是使用
AVPlayer
自己设置音频播放器,并使用设置一个经过时间的观察


如果您一直使用AVAudioPlayer,我相信您可以使用它来监听当前时间的变化:

static NSString *someObservationContext = @"something";

[audioPlayer addObserver:self forKeyPath:@"currentTime" options:0 context:&someObservationContext];
然后实施

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if (context == &someObservationContext) {
        NSTimeInterval t = [(AVAudioPlayer *)object currentTime];
        // do your thing
    } else {
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }

请务必调用
-[NSObject removeObserver:forKeyPath:
以在拆除AVAudioPlayer之前移除观察挂钩。

我尝试使用AVAudioPlayer和观察者执行此操作,但不幸的是,无法调用observeValueForKeyPath。我需要任何框架或init吗?我在那里猜测;我可能错了,它可能不是一个可观察的属性。有没有一个简单的方法来使用AVPlayer?可以使用自定义UI吗?我尝试使用AVAudioPlayer和observer,但不幸的是observeValueForKeyPath没有被调用。我需要任何框架或init吗?我在那里猜测;我可能错了,它可能不是一个可观察的属性。有没有一个简单的方法来使用AVPlayer?可以使用自定义用户界面吗?