Use null seek parameter on method channel

This commit is contained in:
Ryan Heise 2020-06-09 01:49:17 +10:00
parent c0f7feeee8
commit 841bd10822
3 changed files with 9 additions and 11 deletions

View File

@ -267,14 +267,8 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Met
result.success(null); result.success(null);
break; break;
case "seek": case "seek":
Object position = args.get(0); Long position = getLong(args.get(0));
long position2; seek(position == null ? C.TIME_UNSET : position, result);
if (position instanceof Integer) {
position2 = (Integer) position;
} else {
position2 = (Long) position;
}
seek(position2 == -2 ? C.TIME_UNSET : position2, result);
break; break;
case "dispose": case "dispose":
dispose(); dispose();
@ -533,6 +527,10 @@ public class AudioPlayer implements MethodCallHandler, Player.EventListener, Met
sendError("abort", "Connection aborted"); sendError("abort", "Connection aborted");
} }
public static Long getLong(Object o) {
return (o == null || o instanceof Long) ? (Long)o : new Long(((Integer)o).intValue());
}
enum PlaybackState { enum PlaybackState {
none, none,
stopped, stopped,

View File

@ -74,7 +74,8 @@
[self setAutomaticallyWaitsToMinimizeStalling:(BOOL)[args[0] boolValue]]; [self setAutomaticallyWaitsToMinimizeStalling:(BOOL)[args[0] boolValue]];
result(nil); result(nil);
} else if ([@"seek" isEqualToString:call.method]) { } else if ([@"seek" isEqualToString:call.method]) {
[self seek:[args[0] intValue] result:result]; int position = args[0] == [NSNull null] ? -2 : [args[0] intValue];
[self seek:position result:result];
result(nil); result(nil);
} else if ([@"dispose" isEqualToString:call.method]) { } else if ([@"dispose" isEqualToString:call.method]) {
[self dispose]; [self dispose];

View File

@ -441,8 +441,7 @@ class AudioPlayer {
/// any state except for [AudioPlaybackState.none] and /// any state except for [AudioPlaybackState.none] and
/// [AudioPlaybackState.connecting]. /// [AudioPlaybackState.connecting].
Future<void> seek(final Duration position) async { Future<void> seek(final Duration position) async {
await _invokeMethod( await _invokeMethod('seek', [position?.inMilliseconds]);
'seek', [position != null ? position.inMilliseconds : -2]);
} }
/// Release all resources associated with this player. You must invoke this /// Release all resources associated with this player. You must invoke this