support seeking to end of live streams (#108)
* support seeking to end of live streams suggested edit for #96 * fix type casting
This commit is contained in:
parent
ee0c4cd7cd
commit
f66413c007
|
@ -268,11 +268,13 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Met
|
|||
break;
|
||||
case "seek":
|
||||
Object position = args.get(0);
|
||||
long position2;
|
||||
if (position instanceof Integer) {
|
||||
seek((Integer)position, result);
|
||||
position2 = (Integer)position;
|
||||
} else {
|
||||
seek((Long)position, result);
|
||||
position2 = (Long)position;
|
||||
}
|
||||
seek(position2 == -2 ? C.TIME_UNSET : position2, result);
|
||||
break;
|
||||
case "dispose":
|
||||
dispose();
|
||||
|
@ -336,7 +338,7 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Met
|
|||
private long getCurrentPosition() {
|
||||
if (state == PlaybackState.none || state == PlaybackState.connecting) {
|
||||
return 0;
|
||||
} else if (seekPos != null) {
|
||||
} else if (seekPos != null && seekPos != C.TIME_UNSET) {
|
||||
return seekPos;
|
||||
} else {
|
||||
return player.getCurrentPosition();
|
||||
|
|
|
@ -140,7 +140,7 @@
|
|||
- (int)getCurrentPosition {
|
||||
if (_state == none || _state == connecting) {
|
||||
return 0;
|
||||
} else if (_seekPos != -1) {
|
||||
} else if (_seekPos >= 0) {
|
||||
return _seekPos;
|
||||
} else {
|
||||
return (int)(1000 * CMTimeGetSeconds([_player currentTime]));
|
||||
|
@ -360,11 +360,19 @@
|
|||
NSLog(@"seek. enter buffering");
|
||||
_buffering = YES;
|
||||
[self broadcastPlaybackEvent];
|
||||
[_player seekToTime:CMTimeMake(position, 1000)
|
||||
completionHandler:^(BOOL finished) {
|
||||
NSLog(@"seek completed");
|
||||
[self onSeekCompletion:result];
|
||||
}];
|
||||
if (position == -2) {
|
||||
[_player seekToTime:kCMTimePositiveInfinity
|
||||
completionHandler:^(BOOL finished) {
|
||||
NSLog(@"seek completed");
|
||||
[self onSeekCompletion:result];
|
||||
}];
|
||||
} else {
|
||||
[_player seekToTime:CMTimeMake(position, 1000)
|
||||
completionHandler:^(BOOL finished) {
|
||||
NSLog(@"seek completed");
|
||||
[self onSeekCompletion:result];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onSeekCompletion:(FlutterResult)result {
|
||||
|
|
|
@ -421,11 +421,13 @@ class AudioPlayer {
|
|||
[automaticallyWaitsToMinimizeStalling]);
|
||||
}
|
||||
|
||||
/// Seeks to a particular position. It is legal to invoke this method from
|
||||
/// Seeks to a particular position. Specify [null] to seek to the end of live streams.
|
||||
/// It is legal to invoke this method from
|
||||
/// any state except for [AudioPlaybackState.none] and
|
||||
/// [AudioPlaybackState.connecting].
|
||||
Future<void> seek(final Duration position) async {
|
||||
await _invokeMethod('seek', [position.inMilliseconds]);
|
||||
await _invokeMethod(
|
||||
'seek', [position != null ? position.inMilliseconds : -2]);
|
||||
}
|
||||
|
||||
/// Release all resources associated with this player. You must invoke this
|
||||
|
|
Loading…
Reference in New Issue