2012-06-06 46 views
0

我正在開發一個音頻播放器的IOS應用程序。NSTImer值計算

這裏現在我必須移動一個滑塊,它表示歌曲的當前播放曲目

對於實施例我的歌曲時長是6秒現在我有到滑塊從X點= 0到x = 480通過移動實時音頻播放應芬蘭語支付一個循環。 我正在移動基於Nstimer。現在我需要nstimer的nstime間隔正確地移動滑塊到x = 480結束。

myTimer = [NSTimer scheduledTimerWithTimeInterval:timeinterval target:self selector:@selector(updatplayer)userInfo:nil repeatats:YES]; 這裏我需要這個時間間隔值

任何人都可以幫我嗎?

回答

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

喜在這裏我沒有使用我們使用AVAudio播放器和滑塊moviePlayer是我們正在改變這種形象x值來移動它uiimages – naga

+0

- (無效){updatplayer長 = currentPlaybackTime audioPlayer.currentTime; playSlider.center.x =(currentPlaybackTime * progressImage.frame.size.width)/ audioPlayer.duration; }其中progressImage是播放的音頻的加亮區域和playSlider處於ProgressImage這將沿x軸移動指針。 –

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 
+0

我想這個值計算self.myTimeInterval = 6.0;請你可以幫我動態 – naga

+0

我不知道我明白你在問什麼。您可以將該屬性設置爲您執行的任何計算。 –