Implement setSpeed and reset position on stop for iOS

This commit is contained in:
Ryan Heise 2019-12-27 02:45:11 +11:00
parent 788aee577a
commit e77694ade1
2 changed files with 15 additions and 10 deletions

View File

@ -90,7 +90,10 @@ class _MyAppState extends State<MyApp> {
return StreamBuilder<Duration>( return StreamBuilder<Duration>(
stream: _player.getPositionStream(), stream: _player.getPositionStream(),
builder: (context, snapshot) { builder: (context, snapshot) {
final position = snapshot.data ?? Duration.zero; var position = snapshot.data ?? Duration.zero;
if (position > duration) {
position = duration;
}
return SeekBar( return SeekBar(
duration: duration, duration: duration,
position: position, position: position,

View File

@ -95,7 +95,7 @@
long long now = (long long)([[NSDate date] timeIntervalSince1970] * 1000.0); long long now = (long long)([[NSDate date] timeIntervalSince1970] * 1000.0);
int position = [self getCurrentPosition]; int position = [self getCurrentPosition];
long long timeSinceLastUpdate = now - _updateTime; long long timeSinceLastUpdate = now - _updateTime;
long long expectedPosition = _updatePosition + timeSinceLastUpdate; // TODO: * speed long long expectedPosition = _updatePosition + (long long)(timeSinceLastUpdate * _player.rate);
long long drift = position - expectedPosition; long long drift = position - expectedPosition;
// Update if we've drifted or just started observing // Update if we've drifted or just started observing
if (_updateTime == 0L) { if (_updateTime == 0L) {
@ -164,7 +164,7 @@
queue:nil queue:nil
usingBlock:^(NSNotification* note) { usingBlock:^(NSNotification* note) {
NSLog(@"Reached play end time"); NSLog(@"Reached play end time");
[self setPlaybackState:stopped]; [self stop];
} }
]; ];
if (_player) { if (_player) {
@ -252,8 +252,10 @@
- (void)stop { - (void)stop {
[_player pause]; [_player pause];
[[_player currentItem] seekToTime:CMTimeMake(0, 1000)]; [_player seekToTime:CMTimeMake(0, 1000)
[self setPlaybackState:stopped]; completionHandler:^(BOOL finished) {
[self setPlaybackState:stopped];
}];
} }
- (void)setVolume:(float)volume { - (void)setVolume:(float)volume {
@ -261,11 +263,11 @@
} }
- (void)setSpeed:(float)speed { - (void)setSpeed:(float)speed {
//if (speed == 1.0 if (speed == 1.0
// || speed < 1.0 && _player.currentItem.canPlaySlowForward || speed < 1.0 && _player.currentItem.canPlaySlowForward
// || speed > 1.0 && _player.currentItem.canPlayFastForward) { || speed > 1.0 && _player.currentItem.canPlayFastForward) {
// _player.rate = speed; _player.rate = speed;
//} }
} }
- (void)seek:(int)position result:(FlutterResult)result { - (void)seek:(int)position result:(FlutterResult)result {