@shopify/react-native-skia 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +59 -1
- package/android/cpp/rnskia-android/RNSkAndroidVideo.h +4 -0
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkVideo.java +80 -7
- package/cpp/api/JsiVideo.h +32 -7
- package/cpp/rnskia/RNSkVideo.h +4 -0
- package/ios/RNSkia-iOS/RNSkiOSVideo.h +13 -4
- package/ios/RNSkia-iOS/RNSkiOSVideo.mm +65 -67
- package/lib/commonjs/dom/nodes/datatypes/Fitting.js +42 -30
- package/lib/commonjs/dom/nodes/datatypes/Fitting.js.map +1 -1
- package/lib/commonjs/external/reanimated/useVideo.d.ts +16 -4
- package/lib/commonjs/external/reanimated/useVideo.js +76 -14
- package/lib/commonjs/external/reanimated/useVideo.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/FitBox.d.ts +2 -10
- package/lib/commonjs/renderer/components/shapes/FitBox.js +32 -3
- package/lib/commonjs/renderer/components/shapes/FitBox.js.map +1 -1
- package/lib/commonjs/skia/core/Matrix.js +5 -1
- package/lib/commonjs/skia/core/Matrix.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix.js +2 -0
- package/lib/commonjs/skia/types/Matrix.js.map +1 -1
- package/lib/commonjs/skia/types/Video/Video.d.ts +9 -1
- package/lib/commonjs/skia/types/Video/Video.js.map +1 -1
- package/lib/module/dom/nodes/datatypes/Fitting.js +41 -29
- package/lib/module/dom/nodes/datatypes/Fitting.js.map +1 -1
- package/lib/module/external/reanimated/useVideo.d.ts +16 -4
- package/lib/module/external/reanimated/useVideo.js +76 -14
- package/lib/module/external/reanimated/useVideo.js.map +1 -1
- package/lib/module/renderer/components/shapes/FitBox.d.ts +2 -10
- package/lib/module/renderer/components/shapes/FitBox.js +32 -3
- package/lib/module/renderer/components/shapes/FitBox.js.map +1 -1
- package/lib/module/skia/core/Matrix.js +5 -1
- package/lib/module/skia/core/Matrix.js.map +1 -1
- package/lib/module/skia/types/Matrix.js +2 -0
- package/lib/module/skia/types/Matrix.js.map +1 -1
- package/lib/module/skia/types/Video/Video.d.ts +9 -1
- package/lib/module/skia/types/Video/Video.js.map +1 -1
- package/lib/typescript/src/external/reanimated/useVideo.d.ts +16 -4
- package/lib/typescript/src/renderer/components/shapes/FitBox.d.ts +2 -10
- package/lib/typescript/src/skia/types/Video/Video.d.ts +9 -1
- package/package.json +1 -1
- package/src/dom/nodes/datatypes/Fitting.ts +28 -21
- package/src/external/reanimated/useVideo.ts +90 -29
- package/src/renderer/components/shapes/FitBox.tsx +38 -4
- package/src/skia/core/Matrix.ts +4 -2
- package/src/skia/types/Matrix.ts +1 -0
- package/src/skia/types/Video/Video.ts +7 -1
- package/lib/commonjs/external/reanimated/video.d.ts +0 -16
- package/lib/commonjs/external/reanimated/video.js +0 -54
- package/lib/commonjs/external/reanimated/video.js.map +0 -1
- package/lib/module/external/reanimated/video.d.ts +0 -16
- package/lib/module/external/reanimated/video.js +0 -46
- package/lib/module/external/reanimated/video.js.map +0 -1
- package/lib/typescript/src/external/reanimated/video.d.ts +0 -16
- package/src/external/reanimated/video.ts +0 -82
@@ -3,7 +3,7 @@ import React, { useMemo } from "react";
|
|
3
3
|
|
4
4
|
import type { Fit } from "../../../dom/nodes";
|
5
5
|
import { fitRects, rect2rect } from "../../../dom/nodes";
|
6
|
-
import type { SkRect } from "../../../skia/types";
|
6
|
+
import type { SkRect, Transforms3d } from "../../../skia/types";
|
7
7
|
import { Group } from "../Group";
|
8
8
|
|
9
9
|
interface FitProps {
|
@@ -13,9 +13,43 @@ interface FitProps {
|
|
13
13
|
children: ReactNode | ReactNode[];
|
14
14
|
}
|
15
15
|
|
16
|
-
export const fitbox = (
|
17
|
-
|
18
|
-
|
16
|
+
export const fitbox = (
|
17
|
+
fit: Fit,
|
18
|
+
src: SkRect,
|
19
|
+
dst: SkRect,
|
20
|
+
rotation: 0 | 90 | 180 | 270 = 0
|
21
|
+
) => {
|
22
|
+
"worklet";
|
23
|
+
const rects = fitRects(
|
24
|
+
fit,
|
25
|
+
rotation === 90 || rotation === 270
|
26
|
+
? { x: 0, y: 0, width: src.height, height: src.width }
|
27
|
+
: src,
|
28
|
+
dst
|
29
|
+
);
|
30
|
+
const result = rect2rect(rects.src, rects.dst);
|
31
|
+
if (rotation === 90) {
|
32
|
+
return [
|
33
|
+
...result,
|
34
|
+
{ translate: [src.height, 0] },
|
35
|
+
{ rotate: Math.PI / 2 },
|
36
|
+
] as Transforms3d;
|
37
|
+
}
|
38
|
+
if (rotation === 180) {
|
39
|
+
return [
|
40
|
+
...result,
|
41
|
+
{ translate: [src.width, src.height] },
|
42
|
+
{ rotate: Math.PI },
|
43
|
+
] as Transforms3d;
|
44
|
+
}
|
45
|
+
if (rotation === 270) {
|
46
|
+
return [
|
47
|
+
...result,
|
48
|
+
{ translate: [0, src.width] },
|
49
|
+
{ rotate: -Math.PI / 2 },
|
50
|
+
] as Transforms3d;
|
51
|
+
}
|
52
|
+
return result;
|
19
53
|
};
|
20
54
|
|
21
55
|
export const FitBox = ({ fit = "contain", src, dst, children }: FitProps) => {
|
package/src/skia/core/Matrix.ts
CHANGED
@@ -2,5 +2,7 @@ import { Skia } from "../Skia";
|
|
2
2
|
import type { Transforms3d } from "../types";
|
3
3
|
import { processTransform } from "../types";
|
4
4
|
|
5
|
-
export const processTransform2d = (transforms: Transforms3d) =>
|
6
|
-
|
5
|
+
export const processTransform2d = (transforms: Transforms3d) => {
|
6
|
+
"worklet";
|
7
|
+
return processTransform(Skia.Matrix(), transforms);
|
8
|
+
};
|
package/src/skia/types/Matrix.ts
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
import type { SkImage } from "../Image";
|
2
2
|
import type { SkJSIInstance } from "../JsiInstance";
|
3
3
|
|
4
|
+
export type VideoRotation = 0 | 90 | 180 | 270;
|
5
|
+
|
4
6
|
export interface Video extends SkJSIInstance<"Video"> {
|
5
7
|
duration(): number;
|
6
8
|
framerate(): number;
|
7
9
|
nextImage(): SkImage | null;
|
8
10
|
seek(time: number): void;
|
9
|
-
|
11
|
+
rotation(): VideoRotation;
|
12
|
+
size(): { width: number; height: number };
|
13
|
+
pause(): void;
|
14
|
+
play(): void;
|
15
|
+
setVolume(volume: number): void;
|
10
16
|
}
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import type { SharedValue } from "react-native-reanimated";
|
2
|
-
import type { SkImage, Video } from "../../skia/types";
|
3
|
-
export type Animated<T> = SharedValue<T> | T;
|
4
|
-
export interface PlaybackOptions {
|
5
|
-
playbackSpeed: Animated<number>;
|
6
|
-
looping: Animated<boolean>;
|
7
|
-
paused: Animated<boolean>;
|
8
|
-
seek: Animated<number | null>;
|
9
|
-
}
|
10
|
-
type Materialized<T> = {
|
11
|
-
[K in keyof T]: T[K] extends Animated<infer U> ? U : T[K];
|
12
|
-
};
|
13
|
-
export type MaterializedPlaybackOptions = Materialized<Omit<PlaybackOptions, "seek">>;
|
14
|
-
export declare const setFrame: (video: Video, currentFrame: SharedValue<SkImage | null>) => void;
|
15
|
-
export declare const processVideoState: (video: Video | null, duration: number, framerate: number, currentTimestamp: number, options: Materialized<Omit<PlaybackOptions, "seek">>, currentTime: SharedValue<number>, currentFrame: SharedValue<SkImage | null>, lastTimestamp: SharedValue<number>, seek: SharedValue<number | null>) => void;
|
16
|
-
export {};
|
@@ -1,54 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.setFrame = exports.processVideoState = void 0;
|
7
|
-
var _Platform = require("../../Platform");
|
8
|
-
const setFrame = (video, currentFrame) => {
|
9
|
-
"worklet";
|
10
|
-
|
11
|
-
const img = video.nextImage();
|
12
|
-
if (img) {
|
13
|
-
if (currentFrame.value) {
|
14
|
-
currentFrame.value.dispose();
|
15
|
-
}
|
16
|
-
if (_Platform.Platform.OS === "android") {
|
17
|
-
currentFrame.value = img.makeNonTextureImage();
|
18
|
-
} else {
|
19
|
-
currentFrame.value = img;
|
20
|
-
}
|
21
|
-
}
|
22
|
-
};
|
23
|
-
exports.setFrame = setFrame;
|
24
|
-
const processVideoState = (video, duration, framerate, currentTimestamp, options, currentTime, currentFrame, lastTimestamp, seek) => {
|
25
|
-
"worklet";
|
26
|
-
|
27
|
-
if (!video) {
|
28
|
-
return;
|
29
|
-
}
|
30
|
-
if (options.paused) {
|
31
|
-
return;
|
32
|
-
}
|
33
|
-
const delta = currentTimestamp - lastTimestamp.value;
|
34
|
-
const frameDuration = 1000 / framerate;
|
35
|
-
const currentFrameDuration = Math.floor(frameDuration / options.playbackSpeed);
|
36
|
-
if (currentTime.value + delta >= duration && options.looping) {
|
37
|
-
seek.value = 0;
|
38
|
-
}
|
39
|
-
if (seek.value !== null) {
|
40
|
-
video.seek(seek.value);
|
41
|
-
currentTime.value = seek.value;
|
42
|
-
setFrame(video, currentFrame);
|
43
|
-
lastTimestamp.value = currentTimestamp;
|
44
|
-
seek.value = null;
|
45
|
-
return;
|
46
|
-
}
|
47
|
-
if (delta >= currentFrameDuration) {
|
48
|
-
setFrame(video, currentFrame);
|
49
|
-
currentTime.value += delta;
|
50
|
-
lastTimestamp.value = currentTimestamp;
|
51
|
-
}
|
52
|
-
};
|
53
|
-
exports.processVideoState = processVideoState;
|
54
|
-
//# sourceMappingURL=video.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_Platform","require","setFrame","video","currentFrame","img","nextImage","value","dispose","Platform","OS","makeNonTextureImage","exports","processVideoState","duration","framerate","currentTimestamp","options","currentTime","lastTimestamp","seek","paused","delta","frameDuration","currentFrameDuration","Math","floor","playbackSpeed","looping"],"sources":["video.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport type { SkImage, Video } from \"../../skia/types\";\nimport { Platform } from \"../../Platform\";\n\nexport type Animated<T> = SharedValue<T> | T;\n\nexport interface PlaybackOptions {\n playbackSpeed: Animated<number>;\n looping: Animated<boolean>;\n paused: Animated<boolean>;\n seek: Animated<number | null>;\n}\n\ntype Materialized<T> = {\n [K in keyof T]: T[K] extends Animated<infer U> ? U : T[K];\n};\n\nexport type MaterializedPlaybackOptions = Materialized<\n Omit<PlaybackOptions, \"seek\">\n>;\n\nexport const setFrame = (\n video: Video,\n currentFrame: SharedValue<SkImage | null>\n) => {\n \"worklet\";\n const img = video.nextImage();\n if (img) {\n if (currentFrame.value) {\n currentFrame.value.dispose();\n }\n if (Platform.OS === \"android\") {\n currentFrame.value = img.makeNonTextureImage();\n } else {\n currentFrame.value = img;\n }\n }\n};\n\nexport const processVideoState = (\n video: Video | null,\n duration: number,\n framerate: number,\n currentTimestamp: number,\n options: Materialized<Omit<PlaybackOptions, \"seek\">>,\n currentTime: SharedValue<number>,\n currentFrame: SharedValue<SkImage | null>,\n lastTimestamp: SharedValue<number>,\n seek: SharedValue<number | null>\n) => {\n \"worklet\";\n if (!video) {\n return;\n }\n if (options.paused) {\n return;\n }\n const delta = currentTimestamp - lastTimestamp.value;\n\n const frameDuration = 1000 / framerate;\n const currentFrameDuration = Math.floor(\n frameDuration / options.playbackSpeed\n );\n if (currentTime.value + delta >= duration && options.looping) {\n seek.value = 0;\n }\n if (seek.value !== null) {\n video.seek(seek.value);\n currentTime.value = seek.value;\n setFrame(video, currentFrame);\n lastTimestamp.value = currentTimestamp;\n seek.value = null;\n return;\n }\n\n if (delta >= currentFrameDuration) {\n setFrame(video, currentFrame);\n currentTime.value += delta;\n lastTimestamp.value = currentTimestamp;\n }\n};\n"],"mappings":";;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AAmBO,MAAMC,QAAQ,GAAGA,CACtBC,KAAY,EACZC,YAAyC,KACtC;EACH,SAAS;;EACT,MAAMC,GAAG,GAAGF,KAAK,CAACG,SAAS,CAAC,CAAC;EAC7B,IAAID,GAAG,EAAE;IACP,IAAID,YAAY,CAACG,KAAK,EAAE;MACtBH,YAAY,CAACG,KAAK,CAACC,OAAO,CAAC,CAAC;IAC9B;IACA,IAAIC,kBAAQ,CAACC,EAAE,KAAK,SAAS,EAAE;MAC7BN,YAAY,CAACG,KAAK,GAAGF,GAAG,CAACM,mBAAmB,CAAC,CAAC;IAChD,CAAC,MAAM;MACLP,YAAY,CAACG,KAAK,GAAGF,GAAG;IAC1B;EACF;AACF,CAAC;AAACO,OAAA,CAAAV,QAAA,GAAAA,QAAA;AAEK,MAAMW,iBAAiB,GAAGA,CAC/BV,KAAmB,EACnBW,QAAgB,EAChBC,SAAiB,EACjBC,gBAAwB,EACxBC,OAAoD,EACpDC,WAAgC,EAChCd,YAAyC,EACzCe,aAAkC,EAClCC,IAAgC,KAC7B;EACH,SAAS;;EACT,IAAI,CAACjB,KAAK,EAAE;IACV;EACF;EACA,IAAIc,OAAO,CAACI,MAAM,EAAE;IAClB;EACF;EACA,MAAMC,KAAK,GAAGN,gBAAgB,GAAGG,aAAa,CAACZ,KAAK;EAEpD,MAAMgB,aAAa,GAAG,IAAI,GAAGR,SAAS;EACtC,MAAMS,oBAAoB,GAAGC,IAAI,CAACC,KAAK,CACrCH,aAAa,GAAGN,OAAO,CAACU,aAC1B,CAAC;EACD,IAAIT,WAAW,CAACX,KAAK,GAAGe,KAAK,IAAIR,QAAQ,IAAIG,OAAO,CAACW,OAAO,EAAE;IAC5DR,IAAI,CAACb,KAAK,GAAG,CAAC;EAChB;EACA,IAAIa,IAAI,CAACb,KAAK,KAAK,IAAI,EAAE;IACvBJ,KAAK,CAACiB,IAAI,CAACA,IAAI,CAACb,KAAK,CAAC;IACtBW,WAAW,CAACX,KAAK,GAAGa,IAAI,CAACb,KAAK;IAC9BL,QAAQ,CAACC,KAAK,EAAEC,YAAY,CAAC;IAC7Be,aAAa,CAACZ,KAAK,GAAGS,gBAAgB;IACtCI,IAAI,CAACb,KAAK,GAAG,IAAI;IACjB;EACF;EAEA,IAAIe,KAAK,IAAIE,oBAAoB,EAAE;IACjCtB,QAAQ,CAACC,KAAK,EAAEC,YAAY,CAAC;IAC7Bc,WAAW,CAACX,KAAK,IAAIe,KAAK;IAC1BH,aAAa,CAACZ,KAAK,GAAGS,gBAAgB;EACxC;AACF,CAAC;AAACJ,OAAA,CAAAC,iBAAA,GAAAA,iBAAA"}
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import type { SharedValue } from "react-native-reanimated";
|
2
|
-
import type { SkImage, Video } from "../../skia/types";
|
3
|
-
export type Animated<T> = SharedValue<T> | T;
|
4
|
-
export interface PlaybackOptions {
|
5
|
-
playbackSpeed: Animated<number>;
|
6
|
-
looping: Animated<boolean>;
|
7
|
-
paused: Animated<boolean>;
|
8
|
-
seek: Animated<number | null>;
|
9
|
-
}
|
10
|
-
type Materialized<T> = {
|
11
|
-
[K in keyof T]: T[K] extends Animated<infer U> ? U : T[K];
|
12
|
-
};
|
13
|
-
export type MaterializedPlaybackOptions = Materialized<Omit<PlaybackOptions, "seek">>;
|
14
|
-
export declare const setFrame: (video: Video, currentFrame: SharedValue<SkImage | null>) => void;
|
15
|
-
export declare const processVideoState: (video: Video | null, duration: number, framerate: number, currentTimestamp: number, options: Materialized<Omit<PlaybackOptions, "seek">>, currentTime: SharedValue<number>, currentFrame: SharedValue<SkImage | null>, lastTimestamp: SharedValue<number>, seek: SharedValue<number | null>) => void;
|
16
|
-
export {};
|
@@ -1,46 +0,0 @@
|
|
1
|
-
import { Platform } from "../../Platform";
|
2
|
-
export const setFrame = (video, currentFrame) => {
|
3
|
-
"worklet";
|
4
|
-
|
5
|
-
const img = video.nextImage();
|
6
|
-
if (img) {
|
7
|
-
if (currentFrame.value) {
|
8
|
-
currentFrame.value.dispose();
|
9
|
-
}
|
10
|
-
if (Platform.OS === "android") {
|
11
|
-
currentFrame.value = img.makeNonTextureImage();
|
12
|
-
} else {
|
13
|
-
currentFrame.value = img;
|
14
|
-
}
|
15
|
-
}
|
16
|
-
};
|
17
|
-
export const processVideoState = (video, duration, framerate, currentTimestamp, options, currentTime, currentFrame, lastTimestamp, seek) => {
|
18
|
-
"worklet";
|
19
|
-
|
20
|
-
if (!video) {
|
21
|
-
return;
|
22
|
-
}
|
23
|
-
if (options.paused) {
|
24
|
-
return;
|
25
|
-
}
|
26
|
-
const delta = currentTimestamp - lastTimestamp.value;
|
27
|
-
const frameDuration = 1000 / framerate;
|
28
|
-
const currentFrameDuration = Math.floor(frameDuration / options.playbackSpeed);
|
29
|
-
if (currentTime.value + delta >= duration && options.looping) {
|
30
|
-
seek.value = 0;
|
31
|
-
}
|
32
|
-
if (seek.value !== null) {
|
33
|
-
video.seek(seek.value);
|
34
|
-
currentTime.value = seek.value;
|
35
|
-
setFrame(video, currentFrame);
|
36
|
-
lastTimestamp.value = currentTimestamp;
|
37
|
-
seek.value = null;
|
38
|
-
return;
|
39
|
-
}
|
40
|
-
if (delta >= currentFrameDuration) {
|
41
|
-
setFrame(video, currentFrame);
|
42
|
-
currentTime.value += delta;
|
43
|
-
lastTimestamp.value = currentTimestamp;
|
44
|
-
}
|
45
|
-
};
|
46
|
-
//# sourceMappingURL=video.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["Platform","setFrame","video","currentFrame","img","nextImage","value","dispose","OS","makeNonTextureImage","processVideoState","duration","framerate","currentTimestamp","options","currentTime","lastTimestamp","seek","paused","delta","frameDuration","currentFrameDuration","Math","floor","playbackSpeed","looping"],"sources":["video.ts"],"sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport type { SkImage, Video } from \"../../skia/types\";\nimport { Platform } from \"../../Platform\";\n\nexport type Animated<T> = SharedValue<T> | T;\n\nexport interface PlaybackOptions {\n playbackSpeed: Animated<number>;\n looping: Animated<boolean>;\n paused: Animated<boolean>;\n seek: Animated<number | null>;\n}\n\ntype Materialized<T> = {\n [K in keyof T]: T[K] extends Animated<infer U> ? U : T[K];\n};\n\nexport type MaterializedPlaybackOptions = Materialized<\n Omit<PlaybackOptions, \"seek\">\n>;\n\nexport const setFrame = (\n video: Video,\n currentFrame: SharedValue<SkImage | null>\n) => {\n \"worklet\";\n const img = video.nextImage();\n if (img) {\n if (currentFrame.value) {\n currentFrame.value.dispose();\n }\n if (Platform.OS === \"android\") {\n currentFrame.value = img.makeNonTextureImage();\n } else {\n currentFrame.value = img;\n }\n }\n};\n\nexport const processVideoState = (\n video: Video | null,\n duration: number,\n framerate: number,\n currentTimestamp: number,\n options: Materialized<Omit<PlaybackOptions, \"seek\">>,\n currentTime: SharedValue<number>,\n currentFrame: SharedValue<SkImage | null>,\n lastTimestamp: SharedValue<number>,\n seek: SharedValue<number | null>\n) => {\n \"worklet\";\n if (!video) {\n return;\n }\n if (options.paused) {\n return;\n }\n const delta = currentTimestamp - lastTimestamp.value;\n\n const frameDuration = 1000 / framerate;\n const currentFrameDuration = Math.floor(\n frameDuration / options.playbackSpeed\n );\n if (currentTime.value + delta >= duration && options.looping) {\n seek.value = 0;\n }\n if (seek.value !== null) {\n video.seek(seek.value);\n currentTime.value = seek.value;\n setFrame(video, currentFrame);\n lastTimestamp.value = currentTimestamp;\n seek.value = null;\n return;\n }\n\n if (delta >= currentFrameDuration) {\n setFrame(video, currentFrame);\n currentTime.value += delta;\n lastTimestamp.value = currentTimestamp;\n }\n};\n"],"mappings":"AAGA,SAASA,QAAQ,QAAQ,gBAAgB;AAmBzC,OAAO,MAAMC,QAAQ,GAAGA,CACtBC,KAAY,EACZC,YAAyC,KACtC;EACH,SAAS;;EACT,MAAMC,GAAG,GAAGF,KAAK,CAACG,SAAS,CAAC,CAAC;EAC7B,IAAID,GAAG,EAAE;IACP,IAAID,YAAY,CAACG,KAAK,EAAE;MACtBH,YAAY,CAACG,KAAK,CAACC,OAAO,CAAC,CAAC;IAC9B;IACA,IAAIP,QAAQ,CAACQ,EAAE,KAAK,SAAS,EAAE;MAC7BL,YAAY,CAACG,KAAK,GAAGF,GAAG,CAACK,mBAAmB,CAAC,CAAC;IAChD,CAAC,MAAM;MACLN,YAAY,CAACG,KAAK,GAAGF,GAAG;IAC1B;EACF;AACF,CAAC;AAED,OAAO,MAAMM,iBAAiB,GAAGA,CAC/BR,KAAmB,EACnBS,QAAgB,EAChBC,SAAiB,EACjBC,gBAAwB,EACxBC,OAAoD,EACpDC,WAAgC,EAChCZ,YAAyC,EACzCa,aAAkC,EAClCC,IAAgC,KAC7B;EACH,SAAS;;EACT,IAAI,CAACf,KAAK,EAAE;IACV;EACF;EACA,IAAIY,OAAO,CAACI,MAAM,EAAE;IAClB;EACF;EACA,MAAMC,KAAK,GAAGN,gBAAgB,GAAGG,aAAa,CAACV,KAAK;EAEpD,MAAMc,aAAa,GAAG,IAAI,GAAGR,SAAS;EACtC,MAAMS,oBAAoB,GAAGC,IAAI,CAACC,KAAK,CACrCH,aAAa,GAAGN,OAAO,CAACU,aAC1B,CAAC;EACD,IAAIT,WAAW,CAACT,KAAK,GAAGa,KAAK,IAAIR,QAAQ,IAAIG,OAAO,CAACW,OAAO,EAAE;IAC5DR,IAAI,CAACX,KAAK,GAAG,CAAC;EAChB;EACA,IAAIW,IAAI,CAACX,KAAK,KAAK,IAAI,EAAE;IACvBJ,KAAK,CAACe,IAAI,CAACA,IAAI,CAACX,KAAK,CAAC;IACtBS,WAAW,CAACT,KAAK,GAAGW,IAAI,CAACX,KAAK;IAC9BL,QAAQ,CAACC,KAAK,EAAEC,YAAY,CAAC;IAC7Ba,aAAa,CAACV,KAAK,GAAGO,gBAAgB;IACtCI,IAAI,CAACX,KAAK,GAAG,IAAI;IACjB;EACF;EAEA,IAAIa,KAAK,IAAIE,oBAAoB,EAAE;IACjCpB,QAAQ,CAACC,KAAK,EAAEC,YAAY,CAAC;IAC7BY,WAAW,CAACT,KAAK,IAAIa,KAAK;IAC1BH,aAAa,CAACV,KAAK,GAAGO,gBAAgB;EACxC;AACF,CAAC"}
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import type { SharedValue } from "react-native-reanimated";
|
2
|
-
import type { SkImage, Video } from "../../skia/types";
|
3
|
-
export type Animated<T> = SharedValue<T> | T;
|
4
|
-
export interface PlaybackOptions {
|
5
|
-
playbackSpeed: Animated<number>;
|
6
|
-
looping: Animated<boolean>;
|
7
|
-
paused: Animated<boolean>;
|
8
|
-
seek: Animated<number | null>;
|
9
|
-
}
|
10
|
-
type Materialized<T> = {
|
11
|
-
[K in keyof T]: T[K] extends Animated<infer U> ? U : T[K];
|
12
|
-
};
|
13
|
-
export type MaterializedPlaybackOptions = Materialized<Omit<PlaybackOptions, "seek">>;
|
14
|
-
export declare const setFrame: (video: Video, currentFrame: SharedValue<SkImage | null>) => void;
|
15
|
-
export declare const processVideoState: (video: Video | null, duration: number, framerate: number, currentTimestamp: number, options: Materialized<Omit<PlaybackOptions, "seek">>, currentTime: SharedValue<number>, currentFrame: SharedValue<SkImage | null>, lastTimestamp: SharedValue<number>, seek: SharedValue<number | null>) => void;
|
16
|
-
export {};
|
@@ -1,82 +0,0 @@
|
|
1
|
-
import type { SharedValue } from "react-native-reanimated";
|
2
|
-
|
3
|
-
import type { SkImage, Video } from "../../skia/types";
|
4
|
-
import { Platform } from "../../Platform";
|
5
|
-
|
6
|
-
export type Animated<T> = SharedValue<T> | T;
|
7
|
-
|
8
|
-
export interface PlaybackOptions {
|
9
|
-
playbackSpeed: Animated<number>;
|
10
|
-
looping: Animated<boolean>;
|
11
|
-
paused: Animated<boolean>;
|
12
|
-
seek: Animated<number | null>;
|
13
|
-
}
|
14
|
-
|
15
|
-
type Materialized<T> = {
|
16
|
-
[K in keyof T]: T[K] extends Animated<infer U> ? U : T[K];
|
17
|
-
};
|
18
|
-
|
19
|
-
export type MaterializedPlaybackOptions = Materialized<
|
20
|
-
Omit<PlaybackOptions, "seek">
|
21
|
-
>;
|
22
|
-
|
23
|
-
export const setFrame = (
|
24
|
-
video: Video,
|
25
|
-
currentFrame: SharedValue<SkImage | null>
|
26
|
-
) => {
|
27
|
-
"worklet";
|
28
|
-
const img = video.nextImage();
|
29
|
-
if (img) {
|
30
|
-
if (currentFrame.value) {
|
31
|
-
currentFrame.value.dispose();
|
32
|
-
}
|
33
|
-
if (Platform.OS === "android") {
|
34
|
-
currentFrame.value = img.makeNonTextureImage();
|
35
|
-
} else {
|
36
|
-
currentFrame.value = img;
|
37
|
-
}
|
38
|
-
}
|
39
|
-
};
|
40
|
-
|
41
|
-
export const processVideoState = (
|
42
|
-
video: Video | null,
|
43
|
-
duration: number,
|
44
|
-
framerate: number,
|
45
|
-
currentTimestamp: number,
|
46
|
-
options: Materialized<Omit<PlaybackOptions, "seek">>,
|
47
|
-
currentTime: SharedValue<number>,
|
48
|
-
currentFrame: SharedValue<SkImage | null>,
|
49
|
-
lastTimestamp: SharedValue<number>,
|
50
|
-
seek: SharedValue<number | null>
|
51
|
-
) => {
|
52
|
-
"worklet";
|
53
|
-
if (!video) {
|
54
|
-
return;
|
55
|
-
}
|
56
|
-
if (options.paused) {
|
57
|
-
return;
|
58
|
-
}
|
59
|
-
const delta = currentTimestamp - lastTimestamp.value;
|
60
|
-
|
61
|
-
const frameDuration = 1000 / framerate;
|
62
|
-
const currentFrameDuration = Math.floor(
|
63
|
-
frameDuration / options.playbackSpeed
|
64
|
-
);
|
65
|
-
if (currentTime.value + delta >= duration && options.looping) {
|
66
|
-
seek.value = 0;
|
67
|
-
}
|
68
|
-
if (seek.value !== null) {
|
69
|
-
video.seek(seek.value);
|
70
|
-
currentTime.value = seek.value;
|
71
|
-
setFrame(video, currentFrame);
|
72
|
-
lastTimestamp.value = currentTimestamp;
|
73
|
-
seek.value = null;
|
74
|
-
return;
|
75
|
-
}
|
76
|
-
|
77
|
-
if (delta >= currentFrameDuration) {
|
78
|
-
setFrame(video, currentFrame);
|
79
|
-
currentTime.value += delta;
|
80
|
-
lastTimestamp.value = currentTimestamp;
|
81
|
-
}
|
82
|
-
};
|