Trick here is we have to call invalidate(to stop timer) in the same thread.And we can fire a new timer from any where so my final code was like this
-(void) stopPlayBackTimer
{
stopMyTimer = true;
}
-(void) startPlayBackTimer
{
playBackTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateSongPlayBack:) userInfo:nil repeats:YES];
}
-(void) updateMusicPlayerProgress
{
if(stopMyTimer)
{
stopMyTimer = false;
[playBackTimer invalidate];
playBackTimer = nil;
}
MPMediaItem* currentMediaIte = [musicPlayer nowPlayingItem];
long currentPlayBackTime = [musicPlayer currentPlaybackTime];
long totalPlayBackTime = [[currentMediaIte valueForProperty:MPMediaItemPropertyPlaybackDuration] longValue];
float progress = (float)currentPlayBackTime/totalPlayBackTime;
[songProgressIndicator setValue:progress animated:YES];
}

No comments:
Post a Comment