diff --git a/ios/Classes/GeometryBuilders/GeometryBuilder.swift b/ios/Classes/GeometryBuilders/GeometryBuilder.swift index 0b5e4be3..cd92308c 100644 --- a/ios/Classes/GeometryBuilders/GeometryBuilder.swift +++ b/ios/Classes/GeometryBuilders/GeometryBuilder.swift @@ -148,15 +148,23 @@ private func parsePropertyContents(_ dict: Any?) -> Any? { let id = dict["id"] as? String { var videoNode: SKVideoNode + var videoPlayer: AVPlayer? if let videoFilename = dict["filename"] as? String { videoNode = SKVideoNode(fileNamed: videoFilename) } else if let url = dict["url"] as? String, let videoUrl = URL(string: url) { - videoNode = SKVideoNode(url: videoUrl) + videoPlayer = AVPlayer(url: videoUrl) + videoNode = SKVideoNode(avPlayer: videoPlayer!) + } else if let filePath = dict["filePath"] as? String { + let videoFileURL = URL(fileURLWithPath: filePath) + videoPlayer = AVPlayer(url: videoFileURL) + videoNode = SKVideoNode(avPlayer: videoPlayer!) + videoNode.zRotation = .pi } else { return nil } + VideoArkitPlugin.players[id] = videoPlayer VideoArkitPlugin.nodes[id] = videoNode if autoplay { videoNode.play() diff --git a/ios/Classes/VideoArkitPlugin.swift b/ios/Classes/VideoArkitPlugin.swift index a3b32b61..eda6354f 100644 --- a/ios/Classes/VideoArkitPlugin.swift +++ b/ios/Classes/VideoArkitPlugin.swift @@ -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() 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 } diff --git a/lib/src/geometries/material/arkit_material_property.dart b/lib/src/geometries/material/arkit_material_property.dart index e420758e..59e528e5 100644 --- a/lib/src/geometries/material/arkit_material_property.dart +++ b/lib/src/geometries/material/arkit_material_property.dart @@ -30,6 +30,7 @@ abstract class ARKitMaterialProperty { String? filename, String? url, bool? autoplay = true, + String? filePath, }) => ARKitMaterialVideo( filename: filename, @@ -37,6 +38,7 @@ abstract class ARKitMaterialProperty { 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 pause() => _channel.invokeMethod('pause', {'id': id}); + /// Seek video to a specific time. + Future seekTo(Duration duration) => + _channel.invokeMethod('seek', {'id': id, 'seconds': duration.inSeconds}); + static ARKitMaterialVideo fromJson(Map json) => _$ARKitMaterialVideoFromJson(json); diff --git a/lib/src/geometries/material/arkit_material_property.g.dart b/lib/src/geometries/material/arkit_material_property.g.dart index 60d2f2c0..3d4788d4 100644 --- a/lib/src/geometries/material/arkit_material_property.g.dart +++ b/lib/src/geometries/material/arkit_material_property.g.dart @@ -39,6 +39,7 @@ ARKitMaterialVideo _$ARKitMaterialVideoFromJson(Map json) => ARKitMaterialVideo( autoplay: json['autoplay'] as bool? ?? true, filename: json['filename'] as String?, url: json['url'] as String?, + filePath: json['filePath'] as String?, ); Map _$ARKitMaterialVideoToJson(ARKitMaterialVideo instance) { @@ -52,6 +53,7 @@ Map _$ARKitMaterialVideoToJson(ARKitMaterialVideo instance) { writeNotNull('filename', instance.filename); writeNotNull('url', instance.url); + writeNotNull('filePath', instance.filePath); val['width'] = instance.width; val['height'] = instance.height; val['autoplay'] = instance.autoplay;