2014-05-19 81 views

回答

5

如果要复制的音乐应​​用程序显示的时间:

double nowPlayingItemDuration = [[[musicPlayer nowPlayingItem] valueForProperty:MPMediaItemPropertyPlaybackDuration]doubleValue]; 
double currentTime = (double) [musicPlayer currentPlaybackTime]; 
double remainingTime = nowPlayingItemDuration - currentTime; 

NSString *timeElapsed; 
NSString *timeRemaining; 

if (nowPlayingItemDuration >= 3600.0) { 
    timeElapsed = [NSString stringWithFormat: @"%02d:%02d:%02d", 
          (int)currentTime/3600, 
          (int) (currentTime/60)%60, 
          (int) currentTime%60]; 
    timeRemaining = [NSString stringWithFormat:@"- %02d:%02d:%02d", 
          (int)remainingTime/3600, 
          (int) (remainingTime/60)%60, 
          (int) remainingTime%60]; 

} else { 
    timeElapsed = [NSString stringWithFormat: @"%02d:%02d", 
          (int) currentTime/60, 
          (int) currentTime%60]; 
    timeRemaining = [NSString stringWithFormat:@"- %02d:%02d", 
          (int) remainingTime/60, 
          (int) remainingTime%60]; 
} 
+0

谢谢你,我一直在寻找我的音乐播放器.. :) – NorthBlast

0
  • 如果您想要在进度视图中显示,然后按照下面的代码进行显示。它会帮助你。
MPMediaItem *temp; 
    NSTimeInterval trackLength = [[temp valueForProperty:MPMediaItemPropertyPlaybackDuration] doubleValue]; 
    song.songDuration = [temp valueForProperty:MPMediaItemPropertyPlaybackDuration]; 
NSTimer *timer= [NSTimer scheduledTimerWithTimeInterval:1 
               target:self 
               selector:@selector(updateProgress) 
               userInfo:nil 
               repeats:YES]; 

-(void) updateProgress{ 
itemDur++; 
     WASong *song = [self.songObjects objectAtIndex:self.cellIndexPath.row]; 

     CGFloat progress =itemDur/[song.songDuration doubleValue]; 

} 
相关问题