From 59b36d093ebaee88f97f88f10bb745ff0cb9e53a Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Tue, 2 May 2023 13:40:01 -0400 Subject: [PATCH] [video_player] Fix Android lints Removes lint-baseline.xml and fixes all exposed lints. Includes an update of Pigeon to the latest version, to pick up warning fixes in generated code. Part of https://github.com/flutter/flutter/issues/88011 --- .../video_player_android/CHANGELOG.md | 4 + .../video_player_android/android/build.gradle | 1 - .../android/lint-baseline.xml | 653 ------------------ .../videoplayer/CustomSSLSocketFactory.java | 4 +- .../flutter/plugins/videoplayer/Messages.java | 442 ++++++------ .../plugins/videoplayer/QueuingEventSink.java | 4 +- .../plugins/videoplayer/VideoPlayer.java | 6 +- .../videoplayer/VideoPlayerPlugin.java | 46 +- .../lib/src/messages.g.dart | 327 ++++----- .../video_player_android/pubspec.yaml | 4 +- .../video_player_android/test/test_api.g.dart | 131 ++-- 11 files changed, 495 insertions(+), 1127 deletions(-) delete mode 100644 packages/video_player/video_player_android/android/lint-baseline.xml diff --git a/packages/video_player/video_player_android/CHANGELOG.md b/packages/video_player/video_player_android/CHANGELOG.md index a204cb2c6e1..f374fab3ff5 100644 --- a/packages/video_player/video_player_android/CHANGELOG.md +++ b/packages/video_player/video_player_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.4.7 + +* Fixes Java warnings. + ## 2.4.6 * Fixes compatibility with AGP versions older than 4.2. diff --git a/packages/video_player/video_player_android/android/build.gradle b/packages/video_player/video_player_android/android/build.gradle index 613b8ed3c29..aa8b8a06f8b 100644 --- a/packages/video_player/video_player_android/android/build.gradle +++ b/packages/video_player/video_player_android/android/build.gradle @@ -41,7 +41,6 @@ android { checkAllWarnings true warningsAsErrors true disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' - baseline file("lint-baseline.xml") } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 diff --git a/packages/video_player/video_player_android/android/lint-baseline.xml b/packages/video_player/video_player_android/android/lint-baseline.xml deleted file mode 100644 index 4649a80f7b9..00000000000 --- a/packages/video_player/video_player_android/android/lint-baseline.xml +++ /dev/null @@ -1,653 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/CustomSSLSocketFactory.java b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/CustomSSLSocketFactory.java index fb6d2d4108c..731bb9798f6 100644 --- a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/CustomSSLSocketFactory.java +++ b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/CustomSSLSocketFactory.java @@ -13,8 +13,10 @@ import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; +// SSLSocketFactory does not have nullability annotations. +@SuppressWarnings("UnknownNullness") public class CustomSSLSocketFactory extends SSLSocketFactory { - private SSLSocketFactory sslSocketFactory; + private final SSLSocketFactory sslSocketFactory; public CustomSSLSocketFactory() throws KeyManagementException, NoSuchAlgorithmException { SSLContext context = SSLContext.getInstance("TLS"); diff --git a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/Messages.java b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/Messages.java index 6593ebf9c22..e0790af8b86 100644 --- a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/Messages.java +++ b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/Messages.java @@ -1,7 +1,7 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v2.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.2.5), do not edit directly. // See also: https://pub.dev/packages/pigeon package io.flutter.plugins.videoplayer; @@ -16,15 +16,47 @@ import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.HashMap; import java.util.Map; /** Generated class from Pigeon. */ -@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"}) +@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression", "serial"}) public class Messages { + /** Error class for passing custom error details to Flutter via a thrown PlatformException. */ + public static class FlutterError extends RuntimeException { + + /** The error code. */ + public final String code; + + /** The error details. Must be a datatype supported by the api codec. */ + public final Object details; + + public FlutterError(@NonNull String code, @Nullable String message, @Nullable Object details) { + super(message); + this.code = code; + this.details = details; + } + } + + @NonNull + protected static ArrayList wrapError(@NonNull Throwable exception) { + ArrayList errorList = new ArrayList(3); + if (exception instanceof FlutterError) { + FlutterError error = (FlutterError) exception; + errorList.add(error.code); + errorList.add(error.getMessage()); + errorList.add(error.details); + } else { + errorList.add(exception.toString()); + errorList.add(exception.getClass().getSimpleName()); + errorList.add( + "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); + } + return errorList; + } + /** Generated class from Pigeon that represents data sent in messages. */ - public static class TextureMessage { + public static final class TextureMessage { private @NonNull Long textureId; public @NonNull Long getTextureId() { @@ -38,10 +70,11 @@ public void setTextureId(@NonNull Long setterArg) { this.textureId = setterArg; } - /** Constructor is private to enforce null safety; use Builder. */ - private TextureMessage() {} + /** Constructor is non-public to enforce null safety; use Builder. */ + TextureMessage() {} + + public static final class Builder { - public static class Builder { private @Nullable Long textureId; public @NonNull Builder setTextureId(@NonNull Long setterArg) { @@ -57,15 +90,15 @@ public static class Builder { } @NonNull - Map toMap() { - Map toMapResult = new HashMap<>(); - toMapResult.put("textureId", textureId); - return toMapResult; + ArrayList toList() { + ArrayList toListResult = new ArrayList(1); + toListResult.add(textureId); + return toListResult; } - static @NonNull TextureMessage fromMap(@NonNull Map map) { + static @NonNull TextureMessage fromList(@NonNull ArrayList list) { TextureMessage pigeonResult = new TextureMessage(); - Object textureId = map.get("textureId"); + Object textureId = list.get(0); pigeonResult.setTextureId( (textureId == null) ? null @@ -75,7 +108,7 @@ Map toMap() { } /** Generated class from Pigeon that represents data sent in messages. */ - public static class LoopingMessage { + public static final class LoopingMessage { private @NonNull Long textureId; public @NonNull Long getTextureId() { @@ -102,10 +135,11 @@ public void setIsLooping(@NonNull Boolean setterArg) { this.isLooping = setterArg; } - /** Constructor is private to enforce null safety; use Builder. */ - private LoopingMessage() {} + /** Constructor is non-public to enforce null safety; use Builder. */ + LoopingMessage() {} + + public static final class Builder { - public static class Builder { private @Nullable Long textureId; public @NonNull Builder setTextureId(@NonNull Long setterArg) { @@ -129,28 +163,28 @@ public static class Builder { } @NonNull - Map toMap() { - Map toMapResult = new HashMap<>(); - toMapResult.put("textureId", textureId); - toMapResult.put("isLooping", isLooping); - return toMapResult; + ArrayList toList() { + ArrayList toListResult = new ArrayList(2); + toListResult.add(textureId); + toListResult.add(isLooping); + return toListResult; } - static @NonNull LoopingMessage fromMap(@NonNull Map map) { + static @NonNull LoopingMessage fromList(@NonNull ArrayList list) { LoopingMessage pigeonResult = new LoopingMessage(); - Object textureId = map.get("textureId"); + Object textureId = list.get(0); pigeonResult.setTextureId( (textureId == null) ? null : ((textureId instanceof Integer) ? (Integer) textureId : (Long) textureId)); - Object isLooping = map.get("isLooping"); + Object isLooping = list.get(1); pigeonResult.setIsLooping((Boolean) isLooping); return pigeonResult; } } /** Generated class from Pigeon that represents data sent in messages. */ - public static class VolumeMessage { + public static final class VolumeMessage { private @NonNull Long textureId; public @NonNull Long getTextureId() { @@ -177,10 +211,11 @@ public void setVolume(@NonNull Double setterArg) { this.volume = setterArg; } - /** Constructor is private to enforce null safety; use Builder. */ - private VolumeMessage() {} + /** Constructor is non-public to enforce null safety; use Builder. */ + VolumeMessage() {} + + public static final class Builder { - public static class Builder { private @Nullable Long textureId; public @NonNull Builder setTextureId(@NonNull Long setterArg) { @@ -204,28 +239,28 @@ public static class Builder { } @NonNull - Map toMap() { - Map toMapResult = new HashMap<>(); - toMapResult.put("textureId", textureId); - toMapResult.put("volume", volume); - return toMapResult; + ArrayList toList() { + ArrayList toListResult = new ArrayList(2); + toListResult.add(textureId); + toListResult.add(volume); + return toListResult; } - static @NonNull VolumeMessage fromMap(@NonNull Map map) { + static @NonNull VolumeMessage fromList(@NonNull ArrayList list) { VolumeMessage pigeonResult = new VolumeMessage(); - Object textureId = map.get("textureId"); + Object textureId = list.get(0); pigeonResult.setTextureId( (textureId == null) ? null : ((textureId instanceof Integer) ? (Integer) textureId : (Long) textureId)); - Object volume = map.get("volume"); + Object volume = list.get(1); pigeonResult.setVolume((Double) volume); return pigeonResult; } } /** Generated class from Pigeon that represents data sent in messages. */ - public static class PlaybackSpeedMessage { + public static final class PlaybackSpeedMessage { private @NonNull Long textureId; public @NonNull Long getTextureId() { @@ -252,10 +287,11 @@ public void setSpeed(@NonNull Double setterArg) { this.speed = setterArg; } - /** Constructor is private to enforce null safety; use Builder. */ - private PlaybackSpeedMessage() {} + /** Constructor is non-public to enforce null safety; use Builder. */ + PlaybackSpeedMessage() {} + + public static final class Builder { - public static class Builder { private @Nullable Long textureId; public @NonNull Builder setTextureId(@NonNull Long setterArg) { @@ -279,28 +315,28 @@ public static class Builder { } @NonNull - Map toMap() { - Map toMapResult = new HashMap<>(); - toMapResult.put("textureId", textureId); - toMapResult.put("speed", speed); - return toMapResult; + ArrayList toList() { + ArrayList toListResult = new ArrayList(2); + toListResult.add(textureId); + toListResult.add(speed); + return toListResult; } - static @NonNull PlaybackSpeedMessage fromMap(@NonNull Map map) { + static @NonNull PlaybackSpeedMessage fromList(@NonNull ArrayList list) { PlaybackSpeedMessage pigeonResult = new PlaybackSpeedMessage(); - Object textureId = map.get("textureId"); + Object textureId = list.get(0); pigeonResult.setTextureId( (textureId == null) ? null : ((textureId instanceof Integer) ? (Integer) textureId : (Long) textureId)); - Object speed = map.get("speed"); + Object speed = list.get(1); pigeonResult.setSpeed((Double) speed); return pigeonResult; } } /** Generated class from Pigeon that represents data sent in messages. */ - public static class PositionMessage { + public static final class PositionMessage { private @NonNull Long textureId; public @NonNull Long getTextureId() { @@ -327,10 +363,11 @@ public void setPosition(@NonNull Long setterArg) { this.position = setterArg; } - /** Constructor is private to enforce null safety; use Builder. */ - private PositionMessage() {} + /** Constructor is non-public to enforce null safety; use Builder. */ + PositionMessage() {} + + public static final class Builder { - public static class Builder { private @Nullable Long textureId; public @NonNull Builder setTextureId(@NonNull Long setterArg) { @@ -354,21 +391,21 @@ public static class Builder { } @NonNull - Map toMap() { - Map toMapResult = new HashMap<>(); - toMapResult.put("textureId", textureId); - toMapResult.put("position", position); - return toMapResult; + ArrayList toList() { + ArrayList toListResult = new ArrayList(2); + toListResult.add(textureId); + toListResult.add(position); + return toListResult; } - static @NonNull PositionMessage fromMap(@NonNull Map map) { + static @NonNull PositionMessage fromList(@NonNull ArrayList list) { PositionMessage pigeonResult = new PositionMessage(); - Object textureId = map.get("textureId"); + Object textureId = list.get(0); pigeonResult.setTextureId( (textureId == null) ? null : ((textureId instanceof Integer) ? (Integer) textureId : (Long) textureId)); - Object position = map.get("position"); + Object position = list.get(1); pigeonResult.setPosition( (position == null) ? null @@ -378,7 +415,7 @@ Map toMap() { } /** Generated class from Pigeon that represents data sent in messages. */ - public static class CreateMessage { + public static final class CreateMessage { private @Nullable String asset; public @Nullable String getAsset() { @@ -432,10 +469,11 @@ public void setHttpHeaders(@NonNull Map setterArg) { this.httpHeaders = setterArg; } - /** Constructor is private to enforce null safety; use Builder. */ - private CreateMessage() {} + /** Constructor is non-public to enforce null safety; use Builder. */ + CreateMessage() {} + + public static final class Builder { - public static class Builder { private @Nullable String asset; public @NonNull Builder setAsset(@Nullable String setterArg) { @@ -483,34 +521,34 @@ public static class Builder { } @NonNull - Map toMap() { - Map toMapResult = new HashMap<>(); - toMapResult.put("asset", asset); - toMapResult.put("uri", uri); - toMapResult.put("packageName", packageName); - toMapResult.put("formatHint", formatHint); - toMapResult.put("httpHeaders", httpHeaders); - return toMapResult; + ArrayList toList() { + ArrayList toListResult = new ArrayList(5); + toListResult.add(asset); + toListResult.add(uri); + toListResult.add(packageName); + toListResult.add(formatHint); + toListResult.add(httpHeaders); + return toListResult; } - static @NonNull CreateMessage fromMap(@NonNull Map map) { + static @NonNull CreateMessage fromList(@NonNull ArrayList list) { CreateMessage pigeonResult = new CreateMessage(); - Object asset = map.get("asset"); + Object asset = list.get(0); pigeonResult.setAsset((String) asset); - Object uri = map.get("uri"); + Object uri = list.get(1); pigeonResult.setUri((String) uri); - Object packageName = map.get("packageName"); + Object packageName = list.get(2); pigeonResult.setPackageName((String) packageName); - Object formatHint = map.get("formatHint"); + Object formatHint = list.get(3); pigeonResult.setFormatHint((String) formatHint); - Object httpHeaders = map.get("httpHeaders"); + Object httpHeaders = list.get(4); pigeonResult.setHttpHeaders((Map) httpHeaders); return pigeonResult; } } /** Generated class from Pigeon that represents data sent in messages. */ - public static class MixWithOthersMessage { + public static final class MixWithOthersMessage { private @NonNull Boolean mixWithOthers; public @NonNull Boolean getMixWithOthers() { @@ -524,10 +562,11 @@ public void setMixWithOthers(@NonNull Boolean setterArg) { this.mixWithOthers = setterArg; } - /** Constructor is private to enforce null safety; use Builder. */ - private MixWithOthersMessage() {} + /** Constructor is non-public to enforce null safety; use Builder. */ + MixWithOthersMessage() {} + + public static final class Builder { - public static class Builder { private @Nullable Boolean mixWithOthers; public @NonNull Builder setMixWithOthers(@NonNull Boolean setterArg) { @@ -543,15 +582,15 @@ public static class Builder { } @NonNull - Map toMap() { - Map toMapResult = new HashMap<>(); - toMapResult.put("mixWithOthers", mixWithOthers); - return toMapResult; + ArrayList toList() { + ArrayList toListResult = new ArrayList(1); + toListResult.add(mixWithOthers); + return toListResult; } - static @NonNull MixWithOthersMessage fromMap(@NonNull Map map) { + static @NonNull MixWithOthersMessage fromList(@NonNull ArrayList list) { MixWithOthersMessage pigeonResult = new MixWithOthersMessage(); - Object mixWithOthers = map.get("mixWithOthers"); + Object mixWithOthers = list.get(0); pigeonResult.setMixWithOthers((Boolean) mixWithOthers); return pigeonResult; } @@ -563,57 +602,50 @@ private static class AndroidVideoPlayerApiCodec extends StandardMessageCodec { private AndroidVideoPlayerApiCodec() {} @Override - protected Object readValueOfType(byte type, ByteBuffer buffer) { + protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) { switch (type) { case (byte) 128: - return CreateMessage.fromMap((Map) readValue(buffer)); - + return CreateMessage.fromList((ArrayList) readValue(buffer)); case (byte) 129: - return LoopingMessage.fromMap((Map) readValue(buffer)); - + return LoopingMessage.fromList((ArrayList) readValue(buffer)); case (byte) 130: - return MixWithOthersMessage.fromMap((Map) readValue(buffer)); - + return MixWithOthersMessage.fromList((ArrayList) readValue(buffer)); case (byte) 131: - return PlaybackSpeedMessage.fromMap((Map) readValue(buffer)); - + return PlaybackSpeedMessage.fromList((ArrayList) readValue(buffer)); case (byte) 132: - return PositionMessage.fromMap((Map) readValue(buffer)); - + return PositionMessage.fromList((ArrayList) readValue(buffer)); case (byte) 133: - return TextureMessage.fromMap((Map) readValue(buffer)); - + return TextureMessage.fromList((ArrayList) readValue(buffer)); case (byte) 134: - return VolumeMessage.fromMap((Map) readValue(buffer)); - + return VolumeMessage.fromList((ArrayList) readValue(buffer)); default: return super.readValueOfType(type, buffer); } } @Override - protected void writeValue(ByteArrayOutputStream stream, Object value) { + protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) { if (value instanceof CreateMessage) { stream.write(128); - writeValue(stream, ((CreateMessage) value).toMap()); + writeValue(stream, ((CreateMessage) value).toList()); } else if (value instanceof LoopingMessage) { stream.write(129); - writeValue(stream, ((LoopingMessage) value).toMap()); + writeValue(stream, ((LoopingMessage) value).toList()); } else if (value instanceof MixWithOthersMessage) { stream.write(130); - writeValue(stream, ((MixWithOthersMessage) value).toMap()); + writeValue(stream, ((MixWithOthersMessage) value).toList()); } else if (value instanceof PlaybackSpeedMessage) { stream.write(131); - writeValue(stream, ((PlaybackSpeedMessage) value).toMap()); + writeValue(stream, ((PlaybackSpeedMessage) value).toList()); } else if (value instanceof PositionMessage) { stream.write(132); - writeValue(stream, ((PositionMessage) value).toMap()); + writeValue(stream, ((PositionMessage) value).toList()); } else if (value instanceof TextureMessage) { stream.write(133); - writeValue(stream, ((TextureMessage) value).toMap()); + writeValue(stream, ((TextureMessage) value).toList()); } else if (value instanceof VolumeMessage) { stream.write(134); - writeValue(stream, ((VolumeMessage) value).toMap()); + writeValue(stream, ((VolumeMessage) value).toList()); } else { super.writeValue(stream, value); } @@ -622,6 +654,7 @@ protected void writeValue(ByteArrayOutputStream stream, Object value) { /** Generated interface from Pigeon that represents a handler of messages from Flutter. */ public interface AndroidVideoPlayerApi { + void initialize(); @NonNull @@ -647,15 +680,15 @@ public interface AndroidVideoPlayerApi { void setMixWithOthers(@NonNull MixWithOthersMessage msg); /** The codec used by AndroidVideoPlayerApi. */ - static MessageCodec getCodec() { + static @NonNull MessageCodec getCodec() { return AndroidVideoPlayerApiCodec.INSTANCE; } - /** * Sets up an instance of `AndroidVideoPlayerApi` to handle messages through the * `binaryMessenger`. */ - static void setup(BinaryMessenger binaryMessenger, AndroidVideoPlayerApi api) { + static void setup( + @NonNull BinaryMessenger binaryMessenger, @Nullable AndroidVideoPlayerApi api) { { BasicMessageChannel channel = new BasicMessageChannel<>( @@ -663,12 +696,13 @@ static void setup(BinaryMessenger binaryMessenger, AndroidVideoPlayerApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); try { api.initialize(); - wrapped.put("result", null); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, null); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -683,17 +717,15 @@ static void setup(BinaryMessenger binaryMessenger, AndroidVideoPlayerApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + CreateMessage msgArg = (CreateMessage) args.get(0); try { - ArrayList args = (ArrayList) message; - CreateMessage msgArg = (CreateMessage) args.get(0); - if (msgArg == null) { - throw new NullPointerException("msgArg unexpectedly null."); - } TextureMessage output = api.create(msgArg); - wrapped.put("result", output); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -708,17 +740,15 @@ static void setup(BinaryMessenger binaryMessenger, AndroidVideoPlayerApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + TextureMessage msgArg = (TextureMessage) args.get(0); try { - ArrayList args = (ArrayList) message; - TextureMessage msgArg = (TextureMessage) args.get(0); - if (msgArg == null) { - throw new NullPointerException("msgArg unexpectedly null."); - } api.dispose(msgArg); - wrapped.put("result", null); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, null); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -733,17 +763,15 @@ static void setup(BinaryMessenger binaryMessenger, AndroidVideoPlayerApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + LoopingMessage msgArg = (LoopingMessage) args.get(0); try { - ArrayList args = (ArrayList) message; - LoopingMessage msgArg = (LoopingMessage) args.get(0); - if (msgArg == null) { - throw new NullPointerException("msgArg unexpectedly null."); - } api.setLooping(msgArg); - wrapped.put("result", null); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, null); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -758,17 +786,15 @@ static void setup(BinaryMessenger binaryMessenger, AndroidVideoPlayerApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + VolumeMessage msgArg = (VolumeMessage) args.get(0); try { - ArrayList args = (ArrayList) message; - VolumeMessage msgArg = (VolumeMessage) args.get(0); - if (msgArg == null) { - throw new NullPointerException("msgArg unexpectedly null."); - } api.setVolume(msgArg); - wrapped.put("result", null); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, null); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -785,17 +811,15 @@ static void setup(BinaryMessenger binaryMessenger, AndroidVideoPlayerApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + PlaybackSpeedMessage msgArg = (PlaybackSpeedMessage) args.get(0); try { - ArrayList args = (ArrayList) message; - PlaybackSpeedMessage msgArg = (PlaybackSpeedMessage) args.get(0); - if (msgArg == null) { - throw new NullPointerException("msgArg unexpectedly null."); - } api.setPlaybackSpeed(msgArg); - wrapped.put("result", null); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, null); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -810,17 +834,15 @@ static void setup(BinaryMessenger binaryMessenger, AndroidVideoPlayerApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + TextureMessage msgArg = (TextureMessage) args.get(0); try { - ArrayList args = (ArrayList) message; - TextureMessage msgArg = (TextureMessage) args.get(0); - if (msgArg == null) { - throw new NullPointerException("msgArg unexpectedly null."); - } api.play(msgArg); - wrapped.put("result", null); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, null); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -835,17 +857,15 @@ static void setup(BinaryMessenger binaryMessenger, AndroidVideoPlayerApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + TextureMessage msgArg = (TextureMessage) args.get(0); try { - ArrayList args = (ArrayList) message; - TextureMessage msgArg = (TextureMessage) args.get(0); - if (msgArg == null) { - throw new NullPointerException("msgArg unexpectedly null."); - } PositionMessage output = api.position(msgArg); - wrapped.put("result", output); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, output); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -860,17 +880,15 @@ static void setup(BinaryMessenger binaryMessenger, AndroidVideoPlayerApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + PositionMessage msgArg = (PositionMessage) args.get(0); try { - ArrayList args = (ArrayList) message; - PositionMessage msgArg = (PositionMessage) args.get(0); - if (msgArg == null) { - throw new NullPointerException("msgArg unexpectedly null."); - } api.seekTo(msgArg); - wrapped.put("result", null); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, null); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -885,17 +903,15 @@ static void setup(BinaryMessenger binaryMessenger, AndroidVideoPlayerApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + TextureMessage msgArg = (TextureMessage) args.get(0); try { - ArrayList args = (ArrayList) message; - TextureMessage msgArg = (TextureMessage) args.get(0); - if (msgArg == null) { - throw new NullPointerException("msgArg unexpectedly null."); - } api.pause(msgArg); - wrapped.put("result", null); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, null); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -912,17 +928,15 @@ static void setup(BinaryMessenger binaryMessenger, AndroidVideoPlayerApi api) { if (api != null) { channel.setMessageHandler( (message, reply) -> { - Map wrapped = new HashMap<>(); + ArrayList wrapped = new ArrayList(); + ArrayList args = (ArrayList) message; + MixWithOthersMessage msgArg = (MixWithOthersMessage) args.get(0); try { - ArrayList args = (ArrayList) message; - MixWithOthersMessage msgArg = (MixWithOthersMessage) args.get(0); - if (msgArg == null) { - throw new NullPointerException("msgArg unexpectedly null."); - } api.setMixWithOthers(msgArg); - wrapped.put("result", null); - } catch (Error | RuntimeException exception) { - wrapped.put("error", wrapError(exception)); + wrapped.add(0, null); + } catch (Throwable exception) { + ArrayList wrappedError = wrapError(exception); + wrapped = wrappedError; } reply.reply(wrapped); }); @@ -932,14 +946,4 @@ static void setup(BinaryMessenger binaryMessenger, AndroidVideoPlayerApi api) { } } } - - private static Map wrapError(Throwable exception) { - Map errorMap = new HashMap<>(); - errorMap.put("message", exception.toString()); - errorMap.put("code", exception.getClass().getSimpleName()); - errorMap.put( - "details", - "Cause: " + exception.getCause() + ", Stacktrace: " + Log.getStackTraceString(exception)); - return errorMap; - } } diff --git a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/QueuingEventSink.java b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/QueuingEventSink.java index 981389583d2..222a2241614 100644 --- a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/QueuingEventSink.java +++ b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/QueuingEventSink.java @@ -18,7 +18,7 @@ */ final class QueuingEventSink implements EventChannel.EventSink { private EventChannel.EventSink delegate; - private ArrayList eventQueue = new ArrayList<>(); + private final ArrayList eventQueue = new ArrayList<>(); private boolean done = false; public void setDelegate(EventChannel.EventSink delegate) { @@ -69,7 +69,7 @@ private void maybeFlush() { eventQueue.clear(); } - private static class EndOfStreamEvent {} + static class EndOfStreamEvent {} private static class ErrorEvent { String code; diff --git a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java index 4701c7939fb..57fc1037cc7 100644 --- a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java +++ b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java @@ -83,7 +83,7 @@ final class VideoPlayer { DataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(context, httpDataSourceFactory); - MediaSource mediaSource = buildMediaSource(uri, dataSourceFactory, formatHint, context); + MediaSource mediaSource = buildMediaSource(uri, dataSourceFactory, formatHint); exoPlayer.setMediaSource(mediaSource); exoPlayer.prepare(); @@ -124,7 +124,7 @@ public void buildHttpDataSourceFactory(@NonNull Map httpHeaders) } private MediaSource buildMediaSource( - Uri uri, DataSource.Factory mediaDataSourceFactory, String formatHint, Context context) { + Uri uri, DataSource.Factory mediaDataSourceFactory, String formatHint) { int type; if (formatHint == null) { type = Util.inferContentType(uri); @@ -225,7 +225,7 @@ public void onPlaybackStateChanged(final int playbackState) { } @Override - public void onPlayerError(final PlaybackException error) { + public void onPlayerError(@NonNull final PlaybackException error) { setBuffering(false); if (eventSink != null) { eventSink.error("VideoError", "Video player had error " + error, null); diff --git a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayerPlugin.java b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayerPlugin.java index b2dfa944f6d..c0c60279324 100644 --- a/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayerPlugin.java +++ b/packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayerPlugin.java @@ -7,6 +7,7 @@ import android.content.Context; import android.os.Build; import android.util.LongSparseArray; +import androidx.annotation.NonNull; import io.flutter.FlutterInjector; import io.flutter.Log; import io.flutter.embedding.engine.plugins.FlutterPlugin; @@ -32,7 +33,7 @@ public class VideoPlayerPlugin implements FlutterPlugin, AndroidVideoPlayerApi { private static final String TAG = "VideoPlayerPlugin"; private final LongSparseArray videoPlayers = new LongSparseArray<>(); private FlutterState flutterState; - private VideoPlayerOptions options = new VideoPlayerOptions(); + private final VideoPlayerOptions options = new VideoPlayerOptions(); /** Register this with the v2 embedding for the plugin to respond to lifecycle callbacks. */ public VideoPlayerPlugin() {} @@ -51,7 +52,8 @@ private VideoPlayerPlugin(io.flutter.plugin.common.PluginRegistry.Registrar regi /** Registers this with the stable v1 embedding. Will not respond to lifecycle events. */ @SuppressWarnings("deprecation") - public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registrar registrar) { + public static void registerWith( + @NonNull io.flutter.plugin.common.PluginRegistry.Registrar registrar) { final VideoPlayerPlugin plugin = new VideoPlayerPlugin(registrar); registrar.addViewDestroyListener( view -> { @@ -61,7 +63,7 @@ public static void registerWith(io.flutter.plugin.common.PluginRegistry.Registra } @Override - public void onAttachedToEngine(FlutterPluginBinding binding) { + public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) { if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { try { HttpsURLConnection.setDefaultSSLSocketFactory(new CustomSSLSocketFactory()); @@ -87,7 +89,7 @@ public void onAttachedToEngine(FlutterPluginBinding binding) { } @Override - public void onDetachedFromEngine(FlutterPluginBinding binding) { + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { if (flutterState == null) { Log.wtf(TAG, "Detached from the engine before registering to it."); } @@ -116,7 +118,7 @@ public void initialize() { disposeAllPlayers(); } - public TextureMessage create(CreateMessage arg) { + public @NonNull TextureMessage create(@NonNull CreateMessage arg) { TextureRegistry.SurfaceTextureEntry handle = flutterState.textureRegistry.createSurfaceTexture(); EventChannel eventChannel = @@ -139,10 +141,9 @@ public TextureMessage create(CreateMessage arg) { handle, "asset:///" + assetLookupKey, null, - new HashMap(), + new HashMap<>(), options); } else { - @SuppressWarnings("unchecked") Map httpHeaders = arg.getHttpHeaders(); player = new VideoPlayer( @@ -156,37 +157,36 @@ public TextureMessage create(CreateMessage arg) { } videoPlayers.put(handle.id(), player); - TextureMessage result = new TextureMessage.Builder().setTextureId(handle.id()).build(); - return result; + return new TextureMessage.Builder().setTextureId(handle.id()).build(); } - public void dispose(TextureMessage arg) { + public void dispose(@NonNull TextureMessage arg) { VideoPlayer player = videoPlayers.get(arg.getTextureId()); player.dispose(); videoPlayers.remove(arg.getTextureId()); } - public void setLooping(LoopingMessage arg) { + public void setLooping(@NonNull LoopingMessage arg) { VideoPlayer player = videoPlayers.get(arg.getTextureId()); player.setLooping(arg.getIsLooping()); } - public void setVolume(VolumeMessage arg) { + public void setVolume(@NonNull VolumeMessage arg) { VideoPlayer player = videoPlayers.get(arg.getTextureId()); player.setVolume(arg.getVolume()); } - public void setPlaybackSpeed(PlaybackSpeedMessage arg) { + public void setPlaybackSpeed(@NonNull PlaybackSpeedMessage arg) { VideoPlayer player = videoPlayers.get(arg.getTextureId()); player.setPlaybackSpeed(arg.getSpeed()); } - public void play(TextureMessage arg) { + public void play(@NonNull TextureMessage arg) { VideoPlayer player = videoPlayers.get(arg.getTextureId()); player.play(); } - public PositionMessage position(TextureMessage arg) { + public @NonNull PositionMessage position(@NonNull TextureMessage arg) { VideoPlayer player = videoPlayers.get(arg.getTextureId()); PositionMessage result = new PositionMessage.Builder() @@ -197,18 +197,18 @@ public PositionMessage position(TextureMessage arg) { return result; } - public void seekTo(PositionMessage arg) { + public void seekTo(@NonNull PositionMessage arg) { VideoPlayer player = videoPlayers.get(arg.getTextureId()); player.seekTo(arg.getPosition().intValue()); } - public void pause(TextureMessage arg) { + public void pause(@NonNull TextureMessage arg) { VideoPlayer player = videoPlayers.get(arg.getTextureId()); player.pause(); } @Override - public void setMixWithOthers(MixWithOthersMessage arg) { + public void setMixWithOthers(@NonNull MixWithOthersMessage arg) { options.mixWithOthers = arg.getMixWithOthers(); } @@ -221,11 +221,11 @@ private interface KeyForAssetAndPackageName { } private static final class FlutterState { - private final Context applicationContext; - private final BinaryMessenger binaryMessenger; - private final KeyForAssetFn keyForAsset; - private final KeyForAssetAndPackageName keyForAssetAndPackageName; - private final TextureRegistry textureRegistry; + final Context applicationContext; + final BinaryMessenger binaryMessenger; + final KeyForAssetFn keyForAsset; + final KeyForAssetAndPackageName keyForAssetAndPackageName; + final TextureRegistry textureRegistry; FlutterState( Context applicationContext, diff --git a/packages/video_player/video_player_android/lib/src/messages.g.dart b/packages/video_player/video_player_android/lib/src/messages.g.dart index 0dadd2efc67..47ed6a295c8 100644 --- a/packages/video_player/video_player_android/lib/src/messages.g.dart +++ b/packages/video_player/video_player_android/lib/src/messages.g.dart @@ -1,14 +1,14 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v2.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.2.5), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name -// @dart = 2.12 +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import + import 'dart:async'; -import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List; +import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; -import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer; +import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; class TextureMessage { @@ -19,15 +19,15 @@ class TextureMessage { int textureId; Object encode() { - final Map pigeonMap = {}; - pigeonMap['textureId'] = textureId; - return pigeonMap; + return [ + textureId, + ]; } - static TextureMessage decode(Object message) { - final Map pigeonMap = message as Map; + static TextureMessage decode(Object result) { + result as List; return TextureMessage( - textureId: pigeonMap['textureId']! as int, + textureId: result[0]! as int, ); } } @@ -39,20 +39,21 @@ class LoopingMessage { }); int textureId; + bool isLooping; Object encode() { - final Map pigeonMap = {}; - pigeonMap['textureId'] = textureId; - pigeonMap['isLooping'] = isLooping; - return pigeonMap; + return [ + textureId, + isLooping, + ]; } - static LoopingMessage decode(Object message) { - final Map pigeonMap = message as Map; + static LoopingMessage decode(Object result) { + result as List; return LoopingMessage( - textureId: pigeonMap['textureId']! as int, - isLooping: pigeonMap['isLooping']! as bool, + textureId: result[0]! as int, + isLooping: result[1]! as bool, ); } } @@ -64,20 +65,21 @@ class VolumeMessage { }); int textureId; + double volume; Object encode() { - final Map pigeonMap = {}; - pigeonMap['textureId'] = textureId; - pigeonMap['volume'] = volume; - return pigeonMap; + return [ + textureId, + volume, + ]; } - static VolumeMessage decode(Object message) { - final Map pigeonMap = message as Map; + static VolumeMessage decode(Object result) { + result as List; return VolumeMessage( - textureId: pigeonMap['textureId']! as int, - volume: pigeonMap['volume']! as double, + textureId: result[0]! as int, + volume: result[1]! as double, ); } } @@ -89,20 +91,21 @@ class PlaybackSpeedMessage { }); int textureId; + double speed; Object encode() { - final Map pigeonMap = {}; - pigeonMap['textureId'] = textureId; - pigeonMap['speed'] = speed; - return pigeonMap; + return [ + textureId, + speed, + ]; } - static PlaybackSpeedMessage decode(Object message) { - final Map pigeonMap = message as Map; + static PlaybackSpeedMessage decode(Object result) { + result as List; return PlaybackSpeedMessage( - textureId: pigeonMap['textureId']! as int, - speed: pigeonMap['speed']! as double, + textureId: result[0]! as int, + speed: result[1]! as double, ); } } @@ -114,20 +117,21 @@ class PositionMessage { }); int textureId; + int position; Object encode() { - final Map pigeonMap = {}; - pigeonMap['textureId'] = textureId; - pigeonMap['position'] = position; - return pigeonMap; + return [ + textureId, + position, + ]; } - static PositionMessage decode(Object message) { - final Map pigeonMap = message as Map; + static PositionMessage decode(Object result) { + result as List; return PositionMessage( - textureId: pigeonMap['textureId']! as int, - position: pigeonMap['position']! as int, + textureId: result[0]! as int, + position: result[1]! as int, ); } } @@ -142,30 +146,34 @@ class CreateMessage { }); String? asset; + String? uri; + String? packageName; + String? formatHint; + Map httpHeaders; Object encode() { - final Map pigeonMap = {}; - pigeonMap['asset'] = asset; - pigeonMap['uri'] = uri; - pigeonMap['packageName'] = packageName; - pigeonMap['formatHint'] = formatHint; - pigeonMap['httpHeaders'] = httpHeaders; - return pigeonMap; + return [ + asset, + uri, + packageName, + formatHint, + httpHeaders, + ]; } - static CreateMessage decode(Object message) { - final Map pigeonMap = message as Map; + static CreateMessage decode(Object result) { + result as List; return CreateMessage( - asset: pigeonMap['asset'] as String?, - uri: pigeonMap['uri'] as String?, - packageName: pigeonMap['packageName'] as String?, - formatHint: pigeonMap['formatHint'] as String?, - httpHeaders: (pigeonMap['httpHeaders'] as Map?)! - .cast(), + asset: result[0] as String?, + uri: result[1] as String?, + packageName: result[2] as String?, + formatHint: result[3] as String?, + httpHeaders: + (result[4] as Map?)!.cast(), ); } } @@ -178,15 +186,15 @@ class MixWithOthersMessage { bool mixWithOthers; Object encode() { - final Map pigeonMap = {}; - pigeonMap['mixWithOthers'] = mixWithOthers; - return pigeonMap; + return [ + mixWithOthers, + ]; } - static MixWithOthersMessage decode(Object message) { - final Map pigeonMap = message as Map; + static MixWithOthersMessage decode(Object result) { + result as List; return MixWithOthersMessage( - mixWithOthers: pigeonMap['mixWithOthers']! as bool, + mixWithOthers: result[0]! as bool, ); } } @@ -226,25 +234,18 @@ class _AndroidVideoPlayerApiCodec extends StandardMessageCodec { switch (type) { case 128: return CreateMessage.decode(readValue(buffer)!); - case 129: return LoopingMessage.decode(readValue(buffer)!); - case 130: return MixWithOthersMessage.decode(readValue(buffer)!); - case 131: return PlaybackSpeedMessage.decode(readValue(buffer)!); - case 132: return PositionMessage.decode(readValue(buffer)!); - case 133: return TextureMessage.decode(readValue(buffer)!); - case 134: return VolumeMessage.decode(readValue(buffer)!); - default: return super.readValueOfType(type, buffer); } @@ -257,7 +258,6 @@ class AndroidVideoPlayerApi { /// BinaryMessenger will be used which routes to the host platform. AndroidVideoPlayerApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; - final BinaryMessenger? _binaryMessenger; static const MessageCodec codec = _AndroidVideoPlayerApiCodec(); @@ -266,20 +266,17 @@ class AndroidVideoPlayerApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.AndroidVideoPlayerApi.initialize', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send(null) as Map?; - if (replyMap == null) { + final List? replyList = await channel.send(null) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -290,28 +287,26 @@ class AndroidVideoPlayerApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.AndroidVideoPlayerApi.create', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_msg]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_msg]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as TextureMessage?)!; + return (replyList[0] as TextureMessage?)!; } } @@ -319,20 +314,18 @@ class AndroidVideoPlayerApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.AndroidVideoPlayerApi.dispose', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_msg]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_msg]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -343,20 +336,18 @@ class AndroidVideoPlayerApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.AndroidVideoPlayerApi.setLooping', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_msg]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_msg]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -367,20 +358,18 @@ class AndroidVideoPlayerApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.AndroidVideoPlayerApi.setVolume', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_msg]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_msg]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -391,20 +380,18 @@ class AndroidVideoPlayerApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.AndroidVideoPlayerApi.setPlaybackSpeed', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_msg]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_msg]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -415,20 +402,18 @@ class AndroidVideoPlayerApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.AndroidVideoPlayerApi.play', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_msg]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_msg]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -439,28 +424,26 @@ class AndroidVideoPlayerApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.AndroidVideoPlayerApi.position', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_msg]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_msg]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); - } else if (replyMap['result'] == null) { + } else if (replyList[0] == null) { throw PlatformException( code: 'null-error', message: 'Host platform returned null value for non-null return value.', ); } else { - return (replyMap['result'] as PositionMessage?)!; + return (replyList[0] as PositionMessage?)!; } } @@ -468,20 +451,18 @@ class AndroidVideoPlayerApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.AndroidVideoPlayerApi.seekTo', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_msg]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_msg]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -492,20 +473,18 @@ class AndroidVideoPlayerApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.AndroidVideoPlayerApi.pause', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_msg]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_msg]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; @@ -516,20 +495,18 @@ class AndroidVideoPlayerApi { final BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.AndroidVideoPlayerApi.setMixWithOthers', codec, binaryMessenger: _binaryMessenger); - final Map? replyMap = - await channel.send([arg_msg]) as Map?; - if (replyMap == null) { + final List? replyList = + await channel.send([arg_msg]) as List?; + if (replyList == null) { throw PlatformException( code: 'channel-error', message: 'Unable to establish connection on channel.', ); - } else if (replyMap['error'] != null) { - final Map error = - (replyMap['error'] as Map?)!; + } else if (replyList.length > 1) { throw PlatformException( - code: (error['code'] as String?)!, - message: error['message'] as String?, - details: error['details'], + code: replyList[0]! as String, + message: replyList[1] as String?, + details: replyList[2], ); } else { return; diff --git a/packages/video_player/video_player_android/pubspec.yaml b/packages/video_player/video_player_android/pubspec.yaml index dc195b44076..f67375f9e0f 100644 --- a/packages/video_player/video_player_android/pubspec.yaml +++ b/packages/video_player/video_player_android/pubspec.yaml @@ -2,7 +2,7 @@ name: video_player_android description: Android implementation of the video_player plugin. repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22 -version: 2.4.6 +version: 2.4.7 environment: sdk: ">=2.18.0 <4.0.0" @@ -25,4 +25,4 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - pigeon: ^2.0.1 + pigeon: ^9.2.5 diff --git a/packages/video_player/video_player_android/test/test_api.g.dart b/packages/video_player/video_player_android/test/test_api.g.dart index 6361522e247..bb68e71c2fb 100644 --- a/packages/video_player/video_player_android/test/test_api.g.dart +++ b/packages/video_player/video_player_android/test/test_api.g.dart @@ -1,20 +1,16 @@ // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Autogenerated from Pigeon (v2.0.1), do not edit directly. +// Autogenerated from Pigeon (v9.2.5), do not edit directly. // See also: https://pub.dev/packages/pigeon -// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import // ignore_for_file: avoid_relative_lib_imports -// @dart = 2.12 import 'dart:async'; -import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List; -// TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#106316) -// ignore: unnecessary_import -import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer; +import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List; +import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; -// TODO(gaaclarke): This had to be hand tweaked from a relative path. import 'package:video_player_android/src/messages.g.dart'; class _TestHostVideoPlayerApiCodec extends StandardMessageCodec { @@ -52,25 +48,18 @@ class _TestHostVideoPlayerApiCodec extends StandardMessageCodec { switch (type) { case 128: return CreateMessage.decode(readValue(buffer)!); - case 129: return LoopingMessage.decode(readValue(buffer)!); - case 130: return MixWithOthersMessage.decode(readValue(buffer)!); - case 131: return PlaybackSpeedMessage.decode(readValue(buffer)!); - case 132: return PositionMessage.decode(readValue(buffer)!); - case 133: return TextureMessage.decode(readValue(buffer)!); - case 134: return VolumeMessage.decode(readValue(buffer)!); - default: return super.readValueOfType(type, buffer); } @@ -78,19 +67,32 @@ class _TestHostVideoPlayerApiCodec extends StandardMessageCodec { } abstract class TestHostVideoPlayerApi { + static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => + TestDefaultBinaryMessengerBinding.instance; static const MessageCodec codec = _TestHostVideoPlayerApiCodec(); void initialize(); + TextureMessage create(CreateMessage msg); + void dispose(TextureMessage msg); + void setLooping(LoopingMessage msg); + void setVolume(VolumeMessage msg); + void setPlaybackSpeed(PlaybackSpeedMessage msg); + void play(TextureMessage msg); + PositionMessage position(TextureMessage msg); + void seekTo(PositionMessage msg); + void pause(TextureMessage msg); + void setMixWithOthers(MixWithOthersMessage msg); + static void setup(TestHostVideoPlayerApi? api, {BinaryMessenger? binaryMessenger}) { { @@ -98,12 +100,15 @@ abstract class TestHostVideoPlayerApi { 'dev.flutter.pigeon.AndroidVideoPlayerApi.initialize', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { // ignore message api.initialize(); - return {}; + return []; }); } } @@ -112,9 +117,12 @@ abstract class TestHostVideoPlayerApi { 'dev.flutter.pigeon.AndroidVideoPlayerApi.create', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.create was null.'); final List args = (message as List?)!; @@ -122,7 +130,7 @@ abstract class TestHostVideoPlayerApi { assert(arg_msg != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.create was null, expected non-null CreateMessage.'); final TextureMessage output = api.create(arg_msg!); - return {'result': output}; + return [output]; }); } } @@ -131,9 +139,12 @@ abstract class TestHostVideoPlayerApi { 'dev.flutter.pigeon.AndroidVideoPlayerApi.dispose', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.dispose was null.'); final List args = (message as List?)!; @@ -141,7 +152,7 @@ abstract class TestHostVideoPlayerApi { assert(arg_msg != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.dispose was null, expected non-null TextureMessage.'); api.dispose(arg_msg!); - return {}; + return []; }); } } @@ -150,9 +161,12 @@ abstract class TestHostVideoPlayerApi { 'dev.flutter.pigeon.AndroidVideoPlayerApi.setLooping', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.setLooping was null.'); final List args = (message as List?)!; @@ -160,7 +174,7 @@ abstract class TestHostVideoPlayerApi { assert(arg_msg != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.setLooping was null, expected non-null LoopingMessage.'); api.setLooping(arg_msg!); - return {}; + return []; }); } } @@ -169,9 +183,12 @@ abstract class TestHostVideoPlayerApi { 'dev.flutter.pigeon.AndroidVideoPlayerApi.setVolume', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.setVolume was null.'); final List args = (message as List?)!; @@ -179,7 +196,7 @@ abstract class TestHostVideoPlayerApi { assert(arg_msg != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.setVolume was null, expected non-null VolumeMessage.'); api.setVolume(arg_msg!); - return {}; + return []; }); } } @@ -188,9 +205,12 @@ abstract class TestHostVideoPlayerApi { 'dev.flutter.pigeon.AndroidVideoPlayerApi.setPlaybackSpeed', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.setPlaybackSpeed was null.'); final List args = (message as List?)!; @@ -199,7 +219,7 @@ abstract class TestHostVideoPlayerApi { assert(arg_msg != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.setPlaybackSpeed was null, expected non-null PlaybackSpeedMessage.'); api.setPlaybackSpeed(arg_msg!); - return {}; + return []; }); } } @@ -208,9 +228,12 @@ abstract class TestHostVideoPlayerApi { 'dev.flutter.pigeon.AndroidVideoPlayerApi.play', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.play was null.'); final List args = (message as List?)!; @@ -218,7 +241,7 @@ abstract class TestHostVideoPlayerApi { assert(arg_msg != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.play was null, expected non-null TextureMessage.'); api.play(arg_msg!); - return {}; + return []; }); } } @@ -227,9 +250,12 @@ abstract class TestHostVideoPlayerApi { 'dev.flutter.pigeon.AndroidVideoPlayerApi.position', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.position was null.'); final List args = (message as List?)!; @@ -237,7 +263,7 @@ abstract class TestHostVideoPlayerApi { assert(arg_msg != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.position was null, expected non-null TextureMessage.'); final PositionMessage output = api.position(arg_msg!); - return {'result': output}; + return [output]; }); } } @@ -246,9 +272,12 @@ abstract class TestHostVideoPlayerApi { 'dev.flutter.pigeon.AndroidVideoPlayerApi.seekTo', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.seekTo was null.'); final List args = (message as List?)!; @@ -256,7 +285,7 @@ abstract class TestHostVideoPlayerApi { assert(arg_msg != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.seekTo was null, expected non-null PositionMessage.'); api.seekTo(arg_msg!); - return {}; + return []; }); } } @@ -265,9 +294,12 @@ abstract class TestHostVideoPlayerApi { 'dev.flutter.pigeon.AndroidVideoPlayerApi.pause', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.pause was null.'); final List args = (message as List?)!; @@ -275,7 +307,7 @@ abstract class TestHostVideoPlayerApi { assert(arg_msg != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.pause was null, expected non-null TextureMessage.'); api.pause(arg_msg!); - return {}; + return []; }); } } @@ -284,9 +316,12 @@ abstract class TestHostVideoPlayerApi { 'dev.flutter.pigeon.AndroidVideoPlayerApi.setMixWithOthers', codec, binaryMessenger: binaryMessenger); if (api == null) { - channel.setMockMessageHandler(null); + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, null); } else { - channel.setMockMessageHandler((Object? message) async { + _testBinaryMessengerBinding!.defaultBinaryMessenger + .setMockDecodedMessageHandler(channel, + (Object? message) async { assert(message != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.setMixWithOthers was null.'); final List args = (message as List?)!; @@ -295,7 +330,7 @@ abstract class TestHostVideoPlayerApi { assert(arg_msg != null, 'Argument for dev.flutter.pigeon.AndroidVideoPlayerApi.setMixWithOthers was null, expected non-null MixWithOthersMessage.'); api.setMixWithOthers(arg_msg!); - return {}; + return []; }); } }