ios - know MPMusicPlayerController song playing finished -


i implementing 1 ios app playing songs in foreground , background using mpmusicplayercontroller. when in foreground able go next song using below code.

long currentplaybacktime = musicplayer.currentplaybacktime; //nslog(@"%lu",currentplaybacktime); int currenthours = (currentplaybacktime / 3600); int currentminutes = ((currentplaybacktime / 60) - currenthours*60); int currentseconds = (currentplaybacktime % 60);  // total duration of track... long totalplaybacktime = ([[[musicplayer nowplayingitem] valueforproperty: @"playbackduration"] longvalue])-currentplaybacktime; int thours = (totalplaybacktime / 3600); int tmins = ((totalplaybacktime/60) - thours*60); int tsecs = (totalplaybacktime % 60);  float = currentplaybacktime; float b = [[[musicplayer nowplayingitem] valueforproperty: @"playbackduration"] floatvalue];  float flttime= / b; self.positionslider2.value = flttime;  if(thours == 0 && tmins == 0 && tsecs == 0) {     [self nextsong:nil]; } 

but can't go next song when in background why because timers not working in background. , have tried use

  1. mpmusicplayercontrollerplaybackstatedidchangenotification, working in foreground. tell me how go next song when app in background. please let me know if not clear.
  2. tried use

[self addobserver:self forkeypath:@"musicplayer.currentplaybacktime" options:0 context:nil] not working in foreground , background.

any ideas/suggestions helpful.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -