-
Notifications
You must be signed in to change notification settings - Fork 241
Video playback handling in VideoArkitPlugin #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import Flutter | |
|
|
||
| public class VideoArkitPlugin: NSObject, FlutterPlugin { | ||
| static var nodes = [String: SKVideoNode]() | ||
| static var players = [String: AVPlayer]() | ||
|
|
||
| public static func register(with registrar: FlutterPluginRegistrar) { | ||
| let channel = FlutterMethodChannel(name: "arkit_video_playback", binaryMessenger: registrar.messenger()) | ||
|
|
@@ -20,11 +21,14 @@ public class VideoArkitPlugin: NSObject, FlutterPlugin { | |
|
|
||
| switch call.method { | ||
| case "play": | ||
| VideoArkitPlugin.nodes[id]?.play() | ||
| VideoArkitPlugin.players[id]?.play() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't that be a breaking change for folks who use |
||
| case "pause": | ||
| VideoArkitPlugin.nodes[id]?.pause() | ||
| VideoArkitPlugin.players[id]?.pause() | ||
| case "seek": | ||
| VideoArkitPlugin.players[id]?.seek(to: CMTime(seconds: arguments["seconds"] as! Double, preferredTimescale: 600)) | ||
| case "dispose": | ||
| VideoArkitPlugin.nodes.removeValue(forKey: id) | ||
| VideoArkitPlugin.players.removeValue(forKey: id) | ||
| default: | ||
| break | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,13 +30,15 @@ abstract class ARKitMaterialProperty { | |
| String? filename, | ||
| String? url, | ||
| bool? autoplay = true, | ||
| String? filePath, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For users, the distinction between |
||
| }) => | ||
| ARKitMaterialVideo( | ||
| filename: filename, | ||
| url: url, | ||
| width: width, | ||
| height: height, | ||
| autoplay: autoplay ?? true, | ||
| filePath: filePath, | ||
| ); | ||
|
|
||
| final String type; | ||
|
|
@@ -116,11 +118,13 @@ class ARKitMaterialVideo extends ARKitMaterialProperty { | |
| this.autoplay = true, | ||
| this.filename, | ||
| this.url, | ||
| this.filePath, | ||
| }) : id = UniqueKey().toString(), | ||
| super._('video'); | ||
|
|
||
| final String? filename; | ||
| final String? url; | ||
| final String? filePath; | ||
| final int width; | ||
| final int height; | ||
| final bool autoplay; | ||
|
|
@@ -139,6 +143,10 @@ class ARKitMaterialVideo extends ARKitMaterialProperty { | |
| /// Pauses video playback. | ||
| Future<void> pause() => _channel.invokeMethod<void>('pause', {'id': id}); | ||
|
|
||
| /// Seek video to a specific time. | ||
| Future<void> seekTo(Duration duration) => | ||
| _channel.invokeMethod<void>('seek', {'id': id, 'seconds': duration.inSeconds}); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think using milliseconds would be a better fit, as it gives users finer control over the timing. |
||
|
|
||
| static ARKitMaterialVideo fromJson(Map<String, dynamic> json) => | ||
| _$ARKitMaterialVideoFromJson(json); | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid using force unwraps. If
videoPlayercreation fails, calllogPluginErrorinstead.