Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ios/Classes/GeometryBuilders/GeometryBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
Copy link
Owner

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 videoPlayer creation fails, call logPluginError instead.

videoNode.zRotation = .pi
} else {
return nil
}
VideoArkitPlugin.players[id] = videoPlayer
VideoArkitPlugin.nodes[id] = videoNode
if autoplay {
videoNode.play()
Expand Down
8 changes: 6 additions & 2 deletions ios/Classes/VideoArkitPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -20,11 +21,14 @@ public class VideoArkitPlugin: NSObject, FlutterPlugin {

switch call.method {
case "play":
VideoArkitPlugin.nodes[id]?.play()
VideoArkitPlugin.players[id]?.play()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that be a breaking change for folks who use SKVideoNode?

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
}
Expand Down
8 changes: 8 additions & 0 deletions lib/src/geometries/material/arkit_material_property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ abstract class ARKitMaterialProperty {
String? filename,
String? url,
bool? autoplay = true,
String? filePath,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For users, the distinction between filename and filePath might not be obvious. What benefits do we gain from using SKVideoNode(fileNamed: videoFilename)? Do you think it would be more consistent to always rely on SKVideoNode(avPlayer: videoPlayer) instead?

}) =>
ARKitMaterialVideo(
filename: filename,
url: url,
width: width,
height: height,
autoplay: autoplay ?? true,
filePath: filePath,
);

final String type;
Expand Down Expand Up @@ -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;
Expand All @@ -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});
Copy link
Owner

Choose a reason for hiding this comment

The 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);

Expand Down
2 changes: 2 additions & 0 deletions lib/src/geometries/material/arkit_material_property.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.