首页 文章

NSTImer值计算

提问于
浏览
0

我正在为音频播放器开发一个ios应用程序 .

现在我必须移动一个滑块来表示歌曲的当前播放曲目

例如,我的歌曲持续时间是6秒,现在我必须将滑块从x点= 0移动到x = 480,当音频播放应该芬兰它支付一个循环 . 我正在移动基础的Nstimer . 现在我要求nstimer的nstime间隔正确地将滑块移动到x = 480的结尾 .

myTimer = [NSTimer scheduledTimerWithTimeInterval:timeinterval target:self selector:@selector(updatplayer)userInfo:nil repeats:YES];在这里我需要这个时间间隔值

谁能帮我 ?

2 回答

  • 0

    您可以将计时器用作:

    myTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(updatplayer) userInfo:nil repeats:YES];
    
    - (void)updatplayer {
         long currentPlaybackTime = moviePlayer.currentPlaybackTime;
         playSlider.value = currentPlaybackTime / moviePlayer.duration;
    }
    
  • 0

    您可以将时间间隔设置为类属性并从那里访问它 . 例如:

    @interface YourClass ()
    
    @property (nonatomic, assign) NSTimeInterval myTimeInterval);
    
    @end
    
    @implementation YourClass
    
    - (void)methodWithYourTimerInIt {
    
        // ... Do stuff
        self.myTimeInterval = 6.0;
        myTimer = [NSTimer scheduledTimerWithTimeInterval:self.myTimeInterval target:self selector:@selector(updatePlayer) userInfo:nil repeats:YES];
    }
    
    - (void)updatePlayer {
    
        NSLog(@"My time interval is: %f", self.myTimeInterval);
    }
    
    @end
    

相关问题