Skip to content

Commit

Permalink
Update sample app to use new API methods (#372)
Browse files Browse the repository at this point in the history
Migrate sample app to new method signatures, e.g. [self.playerView duration:];
  • Loading branch information
Eric Vargas committed May 8, 2020
1 parent a82ce9d commit 6af4c8f
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,18 @@ - (void)playerView:(YTPlayerView *)ytPlayerView didChangeToState:(YTPlayerState)
}

- (void)playerView:(YTPlayerView *)playerView didPlayTime:(float)playTime {
float progress = playTime/self.playerView.duration;
[self.playerView duration:^(double result, NSError * _Nullable error) {
float progress = playTime/result;
[self.slider setValue:progress];
}];
}

- (IBAction)onSliderChange:(id)sender {
float seekToTime = self.playerView.duration * self.slider.value;
[self.playerView duration:^(double result, NSError * _Nullable error) {
float seekToTime = result * self.slider.value;
[self.playerView seekToSeconds:seekToTime allowSeekAhead:YES];
[self appendStatusText:[NSString stringWithFormat:@"Seeking to time: %.0f seconds\n", seekToTime]];
}];
}

- (IBAction)buttonPressed:(id)sender {
Expand All @@ -65,13 +69,17 @@ - (IBAction)buttonPressed:(id)sender {
} else if (sender == self.pauseButton) {
[self.playerView pauseVideo];
} else if (sender == self.reverseButton) {
float seekToTime = self.playerView.currentTime - 30.0;
[self.playerView seekToSeconds:seekToTime allowSeekAhead:YES];
[self appendStatusText:[NSString stringWithFormat:@"Seeking to time: %.0f seconds\n", seekToTime]];
[self.playerView currentTime:^(float result, NSError * _Nullable error) {
float seekToTime = result - 30.0;
[self.playerView seekToSeconds:seekToTime allowSeekAhead:YES];
[self appendStatusText:[NSString stringWithFormat:@"Seeking to time: %.0f seconds\n", seekToTime]];
}];
} else if (sender == self.forwardButton) {
float seekToTime = self.playerView.currentTime + 30.0;
[self.playerView seekToSeconds:seekToTime allowSeekAhead:YES];
[self appendStatusText:[NSString stringWithFormat:@"Seeking to time: %.0f seconds\n", seekToTime]];
[self.playerView currentTime:^(float result, NSError * _Nullable error) {
float seekToTime = result + 30.0;
[self.playerView seekToSeconds:seekToTime allowSeekAhead:YES];
[self appendStatusText:[NSString stringWithFormat:@"Seeking to time: %.0f seconds\n", seekToTime]];
}];
} else if (sender == self.startButton) {
[self.playerView seekToSeconds:0 allowSeekAhead:YES];
[self appendStatusText:@"Seeking to beginning\n"];
Expand Down

0 comments on commit 6af4c8f

Please sign in to comment.