Mub*_*ikh -1 mpmusicplayercontroller ios
我想在我的应用程序中显示播放歌曲的剩余时间,我的代码:
NSTimeInterval currentTime= musicPlayer.currentPlaybackTime;
NSNumber *duration = [musicPlayer.nowPlayingItem valueForProperty:MPMediaItemPropertyPlaybackDuration];
NSLog(@"Current Playback Time: %f",currentTime);
Run Code Online (Sandbox Code Playgroud)
如果要重现音乐应用中显示的时间:
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];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2155 次 |
| 最近记录: |