7

I am trying to set a UISlider's Value to a AVPlayer's Current Time.

I am trying to use this code audioPlayer.currentTime = nowPlayingSlider.value;

I am getting this error:
Setter method is needed to assign to object using property assignment syntax
How do I get this to work.

Sam Baumgarten
  • 2,231
  • 3
  • 21
  • 46

3 Answers3

10

Here is how I handled this:

-(IBAction) timeScrubberChange:(id) sender{
CMTime t = CMTimeMake(self.nowPlayingTimeScrubber.value, 1);
self.nowPlayingCurrentTime.text = [self formatTimeCodeAsString: t.value];
self.nowPlayingDuration.text = [self formatTimeCodeAsString:(self.actualDuration - t.value)];
[self.avPlayer seekToTime:t];                                
}
John G
  • 128
  • 7
  • 2
    I did something similar to this, but I ran into issues if a user scrobbled with the slider too fast. Essentially, the player loads, the scrobble before playing, and then hit play. It's like the avplayer ignores the seek and sets the currentTime back to 0. – BBonifield Oct 07 '11 at 16:08
3

Sam, check this two methods:

-currentTime and -seekToTime:

Here

They are in AVPlayer class

Community
  • 1
  • 1
Timur Mustafaev
  • 4,869
  • 9
  • 63
  • 109
1

Maybe you have it the other way round?

To set the slider to the current place in the sound it should be:

[nowPlayingSlider setValue:[audioPlayer currentTime]];

To skip in the audio according to a change of the slider:

[audioPlayer setCurrentTime:nowPlayingSlider.value];

Let me know if it works.

Mundi
  • 79,884
  • 17
  • 117
  • 140