2012-06-06 4 views
0

나는 오디오 플레이어를위한 iOS 앱을 개발하고있다. 여기NSTImer 값 계산

지금 내가 노래의 현재 재생중인 트랙을 나타내는 하나 개의 슬라이더를 이동해야

예를 들어 내 노래의 지속 시간이 6 초 지금은에 의해 X 지점에서 = 0 X = 480 슬라이더를 이동해야 할 것입니다 핀란드어로는 한 번의 루프 만 지불하면됩니다. Nstimer 기반으로 움직이고 있습니다. 이제는 nstimer가 슬라이더를 x = 480으로 끝까지 정확하게 이동시키기위한 nstime 간격을 요구했습니다.

myTimer = [NSTimer scheduledTimerWithTimeInterval : 시간 간격 대상 : 셀렉터 : @selector (updatplayer) userInfo : nil repeats : YES]; 여기 내가이 TimeInterval이 값

중 하나가 나를 도울 수이 필요하십니까?

답변

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

안녕 나는 여기 우리가 이동하는 화상 (X)의 값을 변경하는 uiimages을 우리 AVAudio 플레이어 슬라이더 바를 사용 moviePlayer이다 사용하고 있지 않다 – naga

+0

- (무효) updatplayer { 긴 currentPlaybackTime = audioPlayer.currentTime; playSlider.center.x = (currentPlaybackTime * progressImage.frame.size.width)/audioPlayer.duration; } 여기서 progressImage는 재생 된 오디오의 강조 영역이며 playSlider는 x 축을 따라 이동할 ProgressImage의 포인터입니다. –

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; 제발 나를 도와주세요 dynamicaly – naga

+0

난 네가 무엇을 요구하는지 잘 모르겠다. 당신이하는 계산에 상관없이 그 속성을 설정할 수 있습니다. –