![](/img/trans.png)
[英]how to get the remaining time of the Playing song which is played using MPMusicPlayerController?
[英]how to get the remaining time of the song which is played in AVAudioPlayer
我是iPhone新手。 我正在研究音頻播放器。 我必須在音頻播放器中顯示歌曲的當前時間和剩余時間。 在視頻播放器中,它將默認設置,但在音頻播放器中,它將沒有默認設置,因此我編寫了獲取歌曲當前時間的邏輯。 下面的代碼是為此
int minutes = (int)audioPlayer.currentTime / 60;
int seconds = (int)audioPlayer.currentTime % 60;
startDurationLabel.text = [NSString stringWithFormat:@"%d:%02d",minutes,seconds];
這里的audioPlayer是AVAudioPlayer的實例,而startDurationLabel是用於顯示歌曲當前時間的標簽。
但是我努力使這種邏輯起作用並顯示歌曲的剩余時間
如果有人知道這一點,請幫助我...
NSTimeInterval remaining = audioPlayer.duration - audioPlayer.currentTime;
嘗試這個
CGFloat remainingTime = audioPlayer.duration - audioPlayer.currentTime
嘗試這個 -
NSString *strTimeLeft = [self getTimeFromTimeInterval:CMTimeGetSeconds(_player.currentItem.duration) - CMTimeGetSeconds(_player.currentTime)];
在您的班級中添加此方法
- (NSString*)getTimeFromTimeInterval:(NSTimeInterval)timeInterval
{
NSInteger interval = (NSInteger)timeInterval;
NSInteger seconds = interval%60;
NSInteger minutes = (interval/ 60)%60;
//NSInteger hr = (interval/3600)%60;
NSString *strTime = [NSString stringWithFormat:@"%02d:%02d",minutes,seconds];
return strTime;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.