Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 9ae25cf

Browse files
Fix iOS speed
1 parent 412fbfd commit 9ae25cf

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

packages/video_player/video_player/ios/Classes/FLTVideoPlayerPlugin.m

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -360,34 +360,27 @@ - (void)setVolume:(double)volume {
360360
}
361361

362362
- (void)setPlaybackSpeed:(double)speed {
363-
if (speed > 2.0 || speed < 0.0) {
363+
// See https://developer.apple.com/library/archive/qa/qa1772/_index.html for an explanation of
364+
// these checks.
365+
if (speed > 2.0 && !_player.currentItem.canPlayFastForward) {
364366
if (_eventSink != nil) {
365367
_eventSink([FlutterError errorWithCode:@"VideoError"
366-
message:@"Playback speed out of range (0 < speed <= 2)"
368+
message:@"Video cannot be fast-forwarded beyond 2.0x"
367369
details:nil]);
368370
}
369371
return;
370372
}
371373

372-
if (speed == 1.0 || speed == 0.0 || (speed > 1.0 && _player.currentItem.canPlayFastForward) ||
373-
(speed < 1.0 && _player.currentItem.canPlaySlowForward)) {
374-
_player.rate = speed;
375-
return;
376-
}
377-
378-
if (speed > 1.0) {
379-
if (_eventSink != nil) {
380-
_eventSink([FlutterError errorWithCode:@"VideoError"
381-
message:@"Video cannot be fast-forwarded"
382-
details:nil]);
383-
}
384-
} else {
374+
if (speed < 1.0 && !_player.currentItem.canPlaySlowForward) {
385375
if (_eventSink != nil) {
386376
_eventSink([FlutterError errorWithCode:@"VideoError"
387377
message:@"Video cannot be slow-forwarded"
388378
details:nil]);
389379
}
380+
return;
390381
}
382+
383+
_player.rate = speed;
391384
}
392385

393386
- (CVPixelBufferRef)copyPixelBuffer {

packages/video_player/video_player/lib/video_player.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
482482
/// * On web, no exceptions will be thrown, however, different browser
483483
/// implementations will e.g. mute audio.
484484
/// "Gecko mutes the sound outside the range `0.25` to `5.0`" (see https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/playbackRate).
485-
/// * On iOS, you can never go above `2.0` playback speed on any video,
486-
/// however, errors will be thrown for all unsupported options. It is also
487-
/// possible that your specific video cannot be fast-forwarded or slowed
488-
/// down, in which cases the plugin also reports errors.
485+
/// * On iOS, you can sometimes not go above `2.0` playback speed on a video.
486+
/// An error will be thrown for if the option is unsupported. It is also
487+
/// possible that your specific video cannot be slowed down, in which case
488+
/// the plugin also reports errors.
489489
/// * On Android, the handling is similar to web, where the plugin will not
490490
/// report any errors, however, you cannot expect support for all speed
491491
/// values (even though it should go way above `2.0`).

0 commit comments

Comments
 (0)