@capgo/capacitor-video-thumbnails 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapgoCapacitorVideoThumbnails.podspec +17 -0
- package/LICENSE +373 -0
- package/Package.swift +28 -0
- package/README.md +125 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/app/capgo/capacitor/videothumbnails/CapgoVideoThumbnailsPlugin.java +148 -0
- package/dist/docs.json +182 -0
- package/dist/esm/definitions.d.ts +89 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +8 -0
- package/dist/esm/web.js +46 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +60 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +63 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/CapgoVideoThumbnailsPlugin/CapgoVideoThumbnailsPlugin.swift +131 -0
- package/ios/Tests/CapgoVideoThumbnailsPluginTests/CapgoVideoThumbnailsPluginTests.swift +11 -0
- package/package.json +89 -0
package/android/src/main/java/app/capgo/capacitor/videothumbnails/CapgoVideoThumbnailsPlugin.java
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
package app.capgo.capacitor.videothumbnails;
|
|
2
|
+
|
|
3
|
+
import android.graphics.Bitmap;
|
|
4
|
+
import android.media.MediaMetadataRetriever;
|
|
5
|
+
import android.net.Uri;
|
|
6
|
+
import android.util.Log;
|
|
7
|
+
|
|
8
|
+
import com.getcapacitor.JSObject;
|
|
9
|
+
import com.getcapacitor.Plugin;
|
|
10
|
+
import com.getcapacitor.PluginCall;
|
|
11
|
+
import com.getcapacitor.PluginMethod;
|
|
12
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
13
|
+
|
|
14
|
+
import java.io.File;
|
|
15
|
+
import java.io.FileOutputStream;
|
|
16
|
+
import java.io.IOException;
|
|
17
|
+
import java.util.HashMap;
|
|
18
|
+
import java.util.Iterator;
|
|
19
|
+
import java.util.Map;
|
|
20
|
+
import java.util.UUID;
|
|
21
|
+
import java.util.concurrent.ExecutorService;
|
|
22
|
+
import java.util.concurrent.Executors;
|
|
23
|
+
|
|
24
|
+
@CapacitorPlugin(name = "CapgoVideoThumbnails")
|
|
25
|
+
public class CapgoVideoThumbnailsPlugin extends Plugin {
|
|
26
|
+
|
|
27
|
+
private static final String TAG = "CapgoVideoThumbnails";
|
|
28
|
+
private final String pluginVersion = "8.0.0";
|
|
29
|
+
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
30
|
+
|
|
31
|
+
@PluginMethod
|
|
32
|
+
public void getThumbnail(PluginCall call) {
|
|
33
|
+
String sourceUri = call.getString("sourceUri");
|
|
34
|
+
if (sourceUri == null || sourceUri.isEmpty()) {
|
|
35
|
+
call.reject("sourceUri is required");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Double time = call.getDouble("time", 0.0);
|
|
40
|
+
Double quality = call.getDouble("quality", 1.0);
|
|
41
|
+
JSObject headersObj = call.getObject("headers");
|
|
42
|
+
|
|
43
|
+
Map<String, String> headers = new HashMap<>();
|
|
44
|
+
if (headersObj != null) {
|
|
45
|
+
Iterator<String> keys = headersObj.keys();
|
|
46
|
+
while (keys.hasNext()) {
|
|
47
|
+
String key = keys.next();
|
|
48
|
+
String value = headersObj.optString(key, null);
|
|
49
|
+
if (value != null) {
|
|
50
|
+
headers.put(key, value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
executor.execute(() -> {
|
|
56
|
+
try {
|
|
57
|
+
JSObject result = generateThumbnail(sourceUri, time, quality, headers);
|
|
58
|
+
call.resolve(result);
|
|
59
|
+
} catch (Exception e) {
|
|
60
|
+
Log.e(TAG, "Failed to generate thumbnail", e);
|
|
61
|
+
call.reject("Failed to generate thumbnail: " + e.getMessage());
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private JSObject generateThumbnail(String sourceUri, double time, double quality, Map<String, String> headers) throws IOException {
|
|
67
|
+
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
if (sourceUri.startsWith("http://") || sourceUri.startsWith("https://")) {
|
|
71
|
+
if (headers != null && !headers.isEmpty()) {
|
|
72
|
+
retriever.setDataSource(sourceUri, headers);
|
|
73
|
+
} else {
|
|
74
|
+
retriever.setDataSource(sourceUri, new HashMap<>());
|
|
75
|
+
}
|
|
76
|
+
} else if (sourceUri.startsWith("file://")) {
|
|
77
|
+
String path = Uri.parse(sourceUri).getPath();
|
|
78
|
+
if (path == null) {
|
|
79
|
+
throw new IOException("Invalid file URI: " + sourceUri);
|
|
80
|
+
}
|
|
81
|
+
retriever.setDataSource(path);
|
|
82
|
+
} else if (sourceUri.startsWith("content://")) {
|
|
83
|
+
retriever.setDataSource(getContext(), Uri.parse(sourceUri));
|
|
84
|
+
} else {
|
|
85
|
+
// Assume it's a local file path
|
|
86
|
+
File file = new File(sourceUri);
|
|
87
|
+
if (!file.exists()) {
|
|
88
|
+
throw new IOException("File does not exist: " + sourceUri);
|
|
89
|
+
}
|
|
90
|
+
retriever.setDataSource(sourceUri);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Convert milliseconds to microseconds
|
|
94
|
+
long timeUs = (long) (time * 1000);
|
|
95
|
+
|
|
96
|
+
Bitmap bitmap = retriever.getFrameAtTime(timeUs, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
|
|
97
|
+
if (bitmap == null) {
|
|
98
|
+
throw new IOException("Failed to extract frame from video");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Save bitmap to temporary file
|
|
102
|
+
File cacheDir = getContext().getCacheDir();
|
|
103
|
+
String fileName = "thumbnail_" + UUID.randomUUID().toString() + ".jpg";
|
|
104
|
+
File outputFile = new File(cacheDir, fileName);
|
|
105
|
+
|
|
106
|
+
int qualityPercent = (int) (quality * 100);
|
|
107
|
+
if (qualityPercent < 0) qualityPercent = 0;
|
|
108
|
+
if (qualityPercent > 100) qualityPercent = 100;
|
|
109
|
+
|
|
110
|
+
try (FileOutputStream fos = new FileOutputStream(outputFile)) {
|
|
111
|
+
bitmap.compress(Bitmap.CompressFormat.JPEG, qualityPercent, fos);
|
|
112
|
+
fos.flush();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
JSObject result = new JSObject();
|
|
116
|
+
result.put("uri", Uri.fromFile(outputFile).toString());
|
|
117
|
+
result.put("width", bitmap.getWidth());
|
|
118
|
+
result.put("height", bitmap.getHeight());
|
|
119
|
+
|
|
120
|
+
bitmap.recycle();
|
|
121
|
+
|
|
122
|
+
return result;
|
|
123
|
+
} finally {
|
|
124
|
+
try {
|
|
125
|
+
retriever.release();
|
|
126
|
+
} catch (Exception e) {
|
|
127
|
+
Log.w(TAG, "Error releasing MediaMetadataRetriever", e);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@PluginMethod
|
|
133
|
+
public void getPluginVersion(final PluginCall call) {
|
|
134
|
+
try {
|
|
135
|
+
final JSObject ret = new JSObject();
|
|
136
|
+
ret.put("version", this.pluginVersion);
|
|
137
|
+
call.resolve(ret);
|
|
138
|
+
} catch (final Exception e) {
|
|
139
|
+
call.reject("Could not get plugin version", e);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@Override
|
|
144
|
+
protected void handleOnDestroy() {
|
|
145
|
+
super.handleOnDestroy();
|
|
146
|
+
executor.shutdown();
|
|
147
|
+
}
|
|
148
|
+
}
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "CapgoVideoThumbnailsPlugin",
|
|
4
|
+
"slug": "capgovideothumbnailsplugin",
|
|
5
|
+
"docs": "Capacitor Video Thumbnails Plugin interface for generating video thumbnails.",
|
|
6
|
+
"tags": [
|
|
7
|
+
{
|
|
8
|
+
"text": "8.0.0",
|
|
9
|
+
"name": "since"
|
|
10
|
+
}
|
|
11
|
+
],
|
|
12
|
+
"methods": [
|
|
13
|
+
{
|
|
14
|
+
"name": "getThumbnail",
|
|
15
|
+
"signature": "(options: VideoThumbnailsOptions) => Promise<VideoThumbnailsResult>",
|
|
16
|
+
"parameters": [
|
|
17
|
+
{
|
|
18
|
+
"name": "options",
|
|
19
|
+
"docs": "- Options for generating the thumbnail",
|
|
20
|
+
"type": "VideoThumbnailsOptions"
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
"returns": "Promise<VideoThumbnailsResult>",
|
|
24
|
+
"tags": [
|
|
25
|
+
{
|
|
26
|
+
"name": "param",
|
|
27
|
+
"text": "options - Options for generating the thumbnail"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"name": "returns",
|
|
31
|
+
"text": "Promise that resolves with the thumbnail result containing uri, width, and height"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"name": "throws",
|
|
35
|
+
"text": "Error if thumbnail generation fails (e.g., invalid video, network error, unsupported format)"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "since",
|
|
39
|
+
"text": "8.0.0"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "example",
|
|
43
|
+
"text": "```typescript\nconst result = await CapgoVideoThumbnails.getThumbnail({\n sourceUri: 'file:///path/to/video.mp4',\n time: 5000,\n quality: 0.8\n});\nconsole.log('Thumbnail URI:', result.uri);\nconsole.log('Dimensions:', result.width, 'x', result.height);\n```"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"docs": "Generate a thumbnail image from a video file at a specific time position.",
|
|
47
|
+
"complexTypes": [
|
|
48
|
+
"VideoThumbnailsResult",
|
|
49
|
+
"VideoThumbnailsOptions"
|
|
50
|
+
],
|
|
51
|
+
"slug": "getthumbnail"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"name": "getPluginVersion",
|
|
55
|
+
"signature": "() => Promise<{ version: string; }>",
|
|
56
|
+
"parameters": [],
|
|
57
|
+
"returns": "Promise<{ version: string; }>",
|
|
58
|
+
"tags": [
|
|
59
|
+
{
|
|
60
|
+
"name": "returns",
|
|
61
|
+
"text": "Promise that resolves with the plugin version"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"name": "throws",
|
|
65
|
+
"text": "Error if getting the version fails"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"name": "since",
|
|
69
|
+
"text": "8.0.0"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"name": "example",
|
|
73
|
+
"text": "```typescript\nconst { version } = await CapgoVideoThumbnails.getPluginVersion();\nconsole.log('Plugin version:', version);\n```"
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"docs": "Get the native Capacitor plugin version.",
|
|
77
|
+
"complexTypes": [],
|
|
78
|
+
"slug": "getpluginversion"
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
"properties": []
|
|
82
|
+
},
|
|
83
|
+
"interfaces": [
|
|
84
|
+
{
|
|
85
|
+
"name": "VideoThumbnailsResult",
|
|
86
|
+
"slug": "videothumbnailsresult",
|
|
87
|
+
"docs": "Result of thumbnail generation.",
|
|
88
|
+
"tags": [
|
|
89
|
+
{
|
|
90
|
+
"text": "8.0.0",
|
|
91
|
+
"name": "since"
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
"methods": [],
|
|
95
|
+
"properties": [
|
|
96
|
+
{
|
|
97
|
+
"name": "uri",
|
|
98
|
+
"tags": [],
|
|
99
|
+
"docs": "The local URI path to the generated thumbnail image.\nThis can be used directly in img tags or Image components.",
|
|
100
|
+
"complexTypes": [],
|
|
101
|
+
"type": "string"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"name": "width",
|
|
105
|
+
"tags": [],
|
|
106
|
+
"docs": "Width of the generated thumbnail in pixels.",
|
|
107
|
+
"complexTypes": [],
|
|
108
|
+
"type": "number"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"name": "height",
|
|
112
|
+
"tags": [],
|
|
113
|
+
"docs": "Height of the generated thumbnail in pixels.",
|
|
114
|
+
"complexTypes": [],
|
|
115
|
+
"type": "number"
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"name": "VideoThumbnailsOptions",
|
|
121
|
+
"slug": "videothumbnailsoptions",
|
|
122
|
+
"docs": "Options for generating a video thumbnail.",
|
|
123
|
+
"tags": [
|
|
124
|
+
{
|
|
125
|
+
"text": "8.0.0",
|
|
126
|
+
"name": "since"
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
"methods": [],
|
|
130
|
+
"properties": [
|
|
131
|
+
{
|
|
132
|
+
"name": "sourceUri",
|
|
133
|
+
"tags": [],
|
|
134
|
+
"docs": "The URI of the video file. Can be a local file path or a remote URL.\nFor local files, use file:// protocol or absolute path.\nFor remote files, use http:// or https:// protocol.",
|
|
135
|
+
"complexTypes": [],
|
|
136
|
+
"type": "string"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"name": "time",
|
|
140
|
+
"tags": [],
|
|
141
|
+
"docs": "The time position in milliseconds from which to extract the thumbnail.\nDefaults to 0 (first frame).",
|
|
142
|
+
"complexTypes": [],
|
|
143
|
+
"type": "number | undefined"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"name": "quality",
|
|
147
|
+
"tags": [],
|
|
148
|
+
"docs": "Quality of the generated image, from 0.0 (lowest) to 1.0 (highest).\nDefaults to 1.0.",
|
|
149
|
+
"complexTypes": [],
|
|
150
|
+
"type": "number | undefined"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"name": "headers",
|
|
154
|
+
"tags": [],
|
|
155
|
+
"docs": "HTTP headers to include when fetching remote video URIs.\nOnly applicable for remote URLs.",
|
|
156
|
+
"complexTypes": [
|
|
157
|
+
"Record"
|
|
158
|
+
],
|
|
159
|
+
"type": "Record<string, string>"
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
],
|
|
164
|
+
"enums": [],
|
|
165
|
+
"typeAliases": [
|
|
166
|
+
{
|
|
167
|
+
"name": "Record",
|
|
168
|
+
"slug": "record",
|
|
169
|
+
"docs": "Construct a type with a set of properties K of type T",
|
|
170
|
+
"types": [
|
|
171
|
+
{
|
|
172
|
+
"text": "{\r\n [P in K]: T;\r\n}",
|
|
173
|
+
"complexTypes": [
|
|
174
|
+
"K",
|
|
175
|
+
"T"
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
],
|
|
181
|
+
"pluginConfigs": []
|
|
182
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for generating a video thumbnail.
|
|
3
|
+
*
|
|
4
|
+
* @since 8.0.0
|
|
5
|
+
*/
|
|
6
|
+
export interface VideoThumbnailsOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The URI of the video file. Can be a local file path or a remote URL.
|
|
9
|
+
* For local files, use file:// protocol or absolute path.
|
|
10
|
+
* For remote files, use http:// or https:// protocol.
|
|
11
|
+
*/
|
|
12
|
+
sourceUri: string;
|
|
13
|
+
/**
|
|
14
|
+
* The time position in milliseconds from which to extract the thumbnail.
|
|
15
|
+
* Defaults to 0 (first frame).
|
|
16
|
+
*/
|
|
17
|
+
time?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Quality of the generated image, from 0.0 (lowest) to 1.0 (highest).
|
|
20
|
+
* Defaults to 1.0.
|
|
21
|
+
*/
|
|
22
|
+
quality?: number;
|
|
23
|
+
/**
|
|
24
|
+
* HTTP headers to include when fetching remote video URIs.
|
|
25
|
+
* Only applicable for remote URLs.
|
|
26
|
+
*/
|
|
27
|
+
headers?: Record<string, string>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Result of thumbnail generation.
|
|
31
|
+
*
|
|
32
|
+
* @since 8.0.0
|
|
33
|
+
*/
|
|
34
|
+
export interface VideoThumbnailsResult {
|
|
35
|
+
/**
|
|
36
|
+
* The local URI path to the generated thumbnail image.
|
|
37
|
+
* This can be used directly in img tags or Image components.
|
|
38
|
+
*/
|
|
39
|
+
uri: string;
|
|
40
|
+
/**
|
|
41
|
+
* Width of the generated thumbnail in pixels.
|
|
42
|
+
*/
|
|
43
|
+
width: number;
|
|
44
|
+
/**
|
|
45
|
+
* Height of the generated thumbnail in pixels.
|
|
46
|
+
*/
|
|
47
|
+
height: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Capacitor Video Thumbnails Plugin interface for generating video thumbnails.
|
|
51
|
+
*
|
|
52
|
+
* @since 8.0.0
|
|
53
|
+
*/
|
|
54
|
+
export interface CapgoVideoThumbnailsPlugin {
|
|
55
|
+
/**
|
|
56
|
+
* Generate a thumbnail image from a video file at a specific time position.
|
|
57
|
+
*
|
|
58
|
+
* @param options - Options for generating the thumbnail
|
|
59
|
+
* @returns Promise that resolves with the thumbnail result containing uri, width, and height
|
|
60
|
+
* @throws Error if thumbnail generation fails (e.g., invalid video, network error, unsupported format)
|
|
61
|
+
* @since 8.0.0
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const result = await CapgoVideoThumbnails.getThumbnail({
|
|
65
|
+
* sourceUri: 'file:///path/to/video.mp4',
|
|
66
|
+
* time: 5000,
|
|
67
|
+
* quality: 0.8
|
|
68
|
+
* });
|
|
69
|
+
* console.log('Thumbnail URI:', result.uri);
|
|
70
|
+
* console.log('Dimensions:', result.width, 'x', result.height);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
getThumbnail(options: VideoThumbnailsOptions): Promise<VideoThumbnailsResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Get the native Capacitor plugin version.
|
|
76
|
+
*
|
|
77
|
+
* @returns Promise that resolves with the plugin version
|
|
78
|
+
* @throws Error if getting the version fails
|
|
79
|
+
* @since 8.0.0
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const { version } = await CapgoVideoThumbnails.getPluginVersion();
|
|
83
|
+
* console.log('Plugin version:', version);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
getPluginVersion(): Promise<{
|
|
87
|
+
version: string;
|
|
88
|
+
}>;
|
|
89
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Options for generating a video thumbnail.\n *\n * @since 8.0.0\n */\nexport interface VideoThumbnailsOptions {\n /**\n * The URI of the video file. Can be a local file path or a remote URL.\n * For local files, use file:// protocol or absolute path.\n * For remote files, use http:// or https:// protocol.\n */\n sourceUri: string;\n\n /**\n * The time position in milliseconds from which to extract the thumbnail.\n * Defaults to 0 (first frame).\n */\n time?: number;\n\n /**\n * Quality of the generated image, from 0.0 (lowest) to 1.0 (highest).\n * Defaults to 1.0.\n */\n quality?: number;\n\n /**\n * HTTP headers to include when fetching remote video URIs.\n * Only applicable for remote URLs.\n */\n headers?: Record<string, string>;\n}\n\n/**\n * Result of thumbnail generation.\n *\n * @since 8.0.0\n */\nexport interface VideoThumbnailsResult {\n /**\n * The local URI path to the generated thumbnail image.\n * This can be used directly in img tags or Image components.\n */\n uri: string;\n\n /**\n * Width of the generated thumbnail in pixels.\n */\n width: number;\n\n /**\n * Height of the generated thumbnail in pixels.\n */\n height: number;\n}\n\n/**\n * Capacitor Video Thumbnails Plugin interface for generating video thumbnails.\n *\n * @since 8.0.0\n */\nexport interface CapgoVideoThumbnailsPlugin {\n /**\n * Generate a thumbnail image from a video file at a specific time position.\n *\n * @param options - Options for generating the thumbnail\n * @returns Promise that resolves with the thumbnail result containing uri, width, and height\n * @throws Error if thumbnail generation fails (e.g., invalid video, network error, unsupported format)\n * @since 8.0.0\n * @example\n * ```typescript\n * const result = await CapgoVideoThumbnails.getThumbnail({\n * sourceUri: 'file:///path/to/video.mp4',\n * time: 5000,\n * quality: 0.8\n * });\n * console.log('Thumbnail URI:', result.uri);\n * console.log('Dimensions:', result.width, 'x', result.height);\n * ```\n */\n getThumbnail(options: VideoThumbnailsOptions): Promise<VideoThumbnailsResult>;\n\n /**\n * Get the native Capacitor plugin version.\n *\n * @returns Promise that resolves with the plugin version\n * @throws Error if getting the version fails\n * @since 8.0.0\n * @example\n * ```typescript\n * const { version } = await CapgoVideoThumbnails.getPluginVersion();\n * console.log('Plugin version:', version);\n * ```\n */\n getPluginVersion(): Promise<{ version: string }>;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const CapgoVideoThumbnails = registerPlugin('CapgoVideoThumbnails', {
|
|
3
|
+
web: () => import('./web').then((m) => new m.CapgoVideoThumbnailsWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { CapgoVideoThumbnails };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,oBAAoB,GAAG,cAAc,CACzC,sBAAsB,EACtB;IACE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,uBAAuB,EAAE,CAAC;CACxE,CACF,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { CapgoVideoThumbnailsPlugin } from './definitions';\n\nconst CapgoVideoThumbnails = registerPlugin<CapgoVideoThumbnailsPlugin>(\n 'CapgoVideoThumbnails',\n {\n web: () => import('./web').then((m) => new m.CapgoVideoThumbnailsWeb()),\n },\n);\n\nexport * from './definitions';\nexport { CapgoVideoThumbnails };\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { CapgoVideoThumbnailsPlugin, VideoThumbnailsOptions, VideoThumbnailsResult } from './definitions';
|
|
3
|
+
export declare class CapgoVideoThumbnailsWeb extends WebPlugin implements CapgoVideoThumbnailsPlugin {
|
|
4
|
+
getThumbnail(options: VideoThumbnailsOptions): Promise<VideoThumbnailsResult>;
|
|
5
|
+
getPluginVersion(): Promise<{
|
|
6
|
+
version: string;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class CapgoVideoThumbnailsWeb extends WebPlugin {
|
|
3
|
+
async getThumbnail(options) {
|
|
4
|
+
const { sourceUri, time = 0, quality = 1.0 } = options;
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const video = document.createElement('video');
|
|
7
|
+
video.crossOrigin = 'anonymous';
|
|
8
|
+
video.preload = 'metadata';
|
|
9
|
+
video.onloadedmetadata = () => {
|
|
10
|
+
// Seek to the specified time (convert ms to seconds)
|
|
11
|
+
video.currentTime = time / 1000;
|
|
12
|
+
};
|
|
13
|
+
video.onseeked = () => {
|
|
14
|
+
try {
|
|
15
|
+
const canvas = document.createElement('canvas');
|
|
16
|
+
canvas.width = video.videoWidth;
|
|
17
|
+
canvas.height = video.videoHeight;
|
|
18
|
+
const ctx = canvas.getContext('2d');
|
|
19
|
+
if (!ctx) {
|
|
20
|
+
reject(new Error('Failed to get canvas context'));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
24
|
+
const dataUrl = canvas.toDataURL('image/jpeg', quality);
|
|
25
|
+
resolve({
|
|
26
|
+
uri: dataUrl,
|
|
27
|
+
width: canvas.width,
|
|
28
|
+
height: canvas.height,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
reject(new Error(`Failed to extract frame: ${error instanceof Error ? error.message : String(error)}`));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
video.onerror = () => {
|
|
36
|
+
reject(new Error(`Failed to load video from ${sourceUri}`));
|
|
37
|
+
};
|
|
38
|
+
video.src = sourceUri;
|
|
39
|
+
video.load();
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async getPluginVersion() {
|
|
43
|
+
return { version: 'web' };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,MAAM,OAAO,uBACX,SAAQ,SAAS;IAGjB,KAAK,CAAC,YAAY,CAChB,OAA+B;QAE/B,MAAM,EAAE,SAAS,EAAE,IAAI,GAAG,CAAC,EAAE,OAAO,GAAG,GAAG,EAAE,GAAG,OAAO,CAAC;QAEvD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAC9C,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC;YAChC,KAAK,CAAC,OAAO,GAAG,UAAU,CAAC;YAE3B,KAAK,CAAC,gB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,CAAC;YAC9D,CAAC,CAAC;YAEF,KAAK,CAAC,GAAG,GAAG,SAAS,CAAC;YACtB,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CapgoVideoThumbnailsPlugin,\n VideoThumbnailsOptions,\n VideoThumbnailsResult,\n} from './definitions';\n\nexport class CapgoVideoThumbnailsWeb\n extends WebPlugin\n implements CapgoVideoThumbnailsPlugin\n{\n async getThumbnail(\n options: VideoThumbnailsOptions,\n ): Promise<VideoThumbnailsResult> {\n const { sourceUri, time = 0, quality = 1.0 } = options;\n\n return new Promise((resolve, reject) => {\n const video = document.createElement('video');\n video.crossOrigin = 'anonymous';\n video.preload = 'metadata';\n\n video.onloadedmetadata = () => {\n // Seek to the specified time (convert ms to seconds)\n video.currentTime = time / 1000;\n };\n\n video.onseeked = () => {\n try {\n const canvas = document.createElement('canvas');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n\n const ctx = canvas.getContext('2d');\n if (!ctx) {\n reject(new Error('Failed to get canvas context'));\n return;\n }\n\n ctx.drawImage(video, 0, 0, canvas.width, canvas.height);\n\n const dataUrl = canvas.toDataURL('image/jpeg', quality);\n\n resolve({\n uri: dataUrl,\n width: canvas.width,\n height: canvas.height,\n });\n } catch (error) {\n reject(\n new Error(\n `Failed to extract frame: ${error instanceof Error ? error.message : String(error)}`,\n ),\n );\n }\n };\n\n video.onerror = () => {\n reject(new Error(`Failed to load video from ${sourceUri}`));\n };\n\n video.src = sourceUri;\n video.load();\n });\n }\n\n async getPluginVersion(): Promise<{ version: string }> {\n return { version: 'web' };\n }\n}\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const CapgoVideoThumbnails = core.registerPlugin('CapgoVideoThumbnails', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapgoVideoThumbnailsWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class CapgoVideoThumbnailsWeb extends core.WebPlugin {
|
|
10
|
+
async getThumbnail(options) {
|
|
11
|
+
const { sourceUri, time = 0, quality = 1.0 } = options;
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const video = document.createElement('video');
|
|
14
|
+
video.crossOrigin = 'anonymous';
|
|
15
|
+
video.preload = 'metadata';
|
|
16
|
+
video.onloadedmetadata = () => {
|
|
17
|
+
// Seek to the specified time (convert ms to seconds)
|
|
18
|
+
video.currentTime = time / 1000;
|
|
19
|
+
};
|
|
20
|
+
video.onseeked = () => {
|
|
21
|
+
try {
|
|
22
|
+
const canvas = document.createElement('canvas');
|
|
23
|
+
canvas.width = video.videoWidth;
|
|
24
|
+
canvas.height = video.videoHeight;
|
|
25
|
+
const ctx = canvas.getContext('2d');
|
|
26
|
+
if (!ctx) {
|
|
27
|
+
reject(new Error('Failed to get canvas context'));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
31
|
+
const dataUrl = canvas.toDataURL('image/jpeg', quality);
|
|
32
|
+
resolve({
|
|
33
|
+
uri: dataUrl,
|
|
34
|
+
width: canvas.width,
|
|
35
|
+
height: canvas.height,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
reject(new Error(`Failed to extract frame: ${error instanceof Error ? error.message : String(error)}`));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
video.onerror = () => {
|
|
43
|
+
reject(new Error(`Failed to load video from ${sourceUri}`));
|
|
44
|
+
};
|
|
45
|
+
video.src = sourceUri;
|
|
46
|
+
video.load();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async getPluginVersion() {
|
|
50
|
+
return { version: 'web' };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
55
|
+
__proto__: null,
|
|
56
|
+
CapgoVideoThumbnailsWeb: CapgoVideoThumbnailsWeb
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
exports.CapgoVideoThumbnails = CapgoVideoThumbnails;
|
|
60
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapgoVideoThumbnails = registerPlugin('CapgoVideoThumbnails', {\n web: () => import('./web').then((m) => new m.CapgoVideoThumbnailsWeb()),\n});\nexport * from './definitions';\nexport { CapgoVideoThumbnails };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapgoVideoThumbnailsWeb extends WebPlugin {\n async getThumbnail(options) {\n const { sourceUri, time = 0, quality = 1.0 } = options;\n return new Promise((resolve, reject) => {\n const video = document.createElement('video');\n video.crossOrigin = 'anonymous';\n video.preload = 'metadata';\n video.onloadedmetadata = () => {\n // Seek to the specified time (convert ms to seconds)\n video.currentTime = time / 1000;\n };\n video.onseeked = () => {\n try {\n const canvas = document.createElement('canvas');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n const ctx = canvas.getContext('2d');\n if (!ctx) {\n reject(new Error('Failed to get canvas context'));\n return;\n }\n ctx.drawImage(video, 0, 0, canvas.width, canvas.height);\n const dataUrl = canvas.toDataURL('image/jpeg', quality);\n resolve({\n uri: dataUrl,\n width: canvas.width,\n height: canvas.height,\n });\n }\n catch (error) {\n reject(new Error(`Failed to extract frame: ${error instanceof Error ? error.message : String(error)}`));\n }\n };\n video.onerror = () => {\n reject(new Error(`Failed to load video from ${sourceUri}`));\n };\n video.src = sourceUri;\n video.load();\n });\n }\n async getPluginVersion() {\n return { version: 'web' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,oBAAoB,GAAGA,mBAAc,CAAC,sBAAsB,EAAE;AACpE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,uBAAuB,EAAE,CAAC;AAC3E,CAAC;;ACFM,MAAM,uBAAuB,SAASC,cAAS,CAAC;AACvD,IAAI,MAAM,YAAY,CAAC,OAAO,EAAE;AAChC,QAAQ,MAAM,EAAE,SAAS,EAAE,IAAI,GAAG,CAAC,EAAE,OAAO,GAAG,GAAG,EAAE,GAAG,OAAO;AAC9D,QAAQ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AAChD,YAAY,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC;AACzD,YAAY,KAAK,CAAC,WAAW,GAAG,WAAW;AAC3C,YAAY,KAAK,CAAC,OAAO,GAAG,UAAU;AACtC,YAAY,KAAK,CAAC,gBAAgB,GAAG,MAAM;AAC3C;AACA,gBAAgB,KAAK,CAAC,WAAW,GAAG,IAAI,GAAG,IAAI;AAC/C,YAAY,CAAC;AACb,YAAY,KAAK,CAAC,QAAQ,GAAG,MAAM;AACnC,gBAAgB,IAAI;AACpB,oBAAoB,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;AACnE,oBAAoB,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,UAAU;AACnD,oBAAoB,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,WAAW;AACrD,oBAAoB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC;AACvD,oBAAoB,IAAI,CAAC,GAAG,EAAE;AAC9B,wBAAwB,MAAM,CAAC,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;AACzE,wBAAwB;AACxB,oBAAoB;AACpB,oBAAoB,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;AAC3E,oBAAoB,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC;AAC3E,oBAAoB,OAAO,CAAC;AAC5B,wBAAwB,GAAG,EAAE,OAAO;AACpC,wBAAwB,KAAK,EAAE,MAAM,CAAC,KAAK;AAC3C,wBAAwB,MAAM,EAAE,MAAM,CAAC,MAAM;AAC7C,qBAAqB,CAAC;AACtB,gBAAgB;AAChB,gBAAgB,OAAO,KAAK,EAAE;AAC9B,oBAAoB,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,yBAAyB,EAAE,KAAK,YAAY,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3H,gBAAgB;AAChB,YAAY,CAAC;AACb,YAAY,KAAK,CAAC,OAAO,GAAG,MAAM;AAClC,gBAAgB,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,0BAA0B,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;AAC3E,YAAY,CAAC;AACb,YAAY,KAAK,CAAC,GAAG,GAAG,SAAS;AACjC,YAAY,KAAK,CAAC,IAAI,EAAE;AACxB,QAAQ,CAAC,CAAC;AACV,IAAI;AACJ,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE;AACjC,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var capacitorCapgoVideoThumbnails = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const CapgoVideoThumbnails = core.registerPlugin('CapgoVideoThumbnails', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.CapgoVideoThumbnailsWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class CapgoVideoThumbnailsWeb extends core.WebPlugin {
|
|
9
|
+
async getThumbnail(options) {
|
|
10
|
+
const { sourceUri, time = 0, quality = 1.0 } = options;
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const video = document.createElement('video');
|
|
13
|
+
video.crossOrigin = 'anonymous';
|
|
14
|
+
video.preload = 'metadata';
|
|
15
|
+
video.onloadedmetadata = () => {
|
|
16
|
+
// Seek to the specified time (convert ms to seconds)
|
|
17
|
+
video.currentTime = time / 1000;
|
|
18
|
+
};
|
|
19
|
+
video.onseeked = () => {
|
|
20
|
+
try {
|
|
21
|
+
const canvas = document.createElement('canvas');
|
|
22
|
+
canvas.width = video.videoWidth;
|
|
23
|
+
canvas.height = video.videoHeight;
|
|
24
|
+
const ctx = canvas.getContext('2d');
|
|
25
|
+
if (!ctx) {
|
|
26
|
+
reject(new Error('Failed to get canvas context'));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
30
|
+
const dataUrl = canvas.toDataURL('image/jpeg', quality);
|
|
31
|
+
resolve({
|
|
32
|
+
uri: dataUrl,
|
|
33
|
+
width: canvas.width,
|
|
34
|
+
height: canvas.height,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
reject(new Error(`Failed to extract frame: ${error instanceof Error ? error.message : String(error)}`));
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
video.onerror = () => {
|
|
42
|
+
reject(new Error(`Failed to load video from ${sourceUri}`));
|
|
43
|
+
};
|
|
44
|
+
video.src = sourceUri;
|
|
45
|
+
video.load();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async getPluginVersion() {
|
|
49
|
+
return { version: 'web' };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
54
|
+
__proto__: null,
|
|
55
|
+
CapgoVideoThumbnailsWeb: CapgoVideoThumbnailsWeb
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
exports.CapgoVideoThumbnails = CapgoVideoThumbnails;
|
|
59
|
+
|
|
60
|
+
return exports;
|
|
61
|
+
|
|
62
|
+
})({}, capacitorExports);
|
|
63
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapgoVideoThumbnails = registerPlugin('CapgoVideoThumbnails', {\n web: () => import('./web').then((m) => new m.CapgoVideoThumbnailsWeb()),\n});\nexport * from './definitions';\nexport { CapgoVideoThumbnails };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapgoVideoThumbnailsWeb extends WebPlugin {\n async getThumbnail(options) {\n const { sourceUri, time = 0, quality = 1.0 } = options;\n return new Promise((resolve, reject) => {\n const video = document.createElement('video');\n video.crossOrigin = 'anonymous';\n video.preload = 'metadata';\n video.onloadedmetadata = () => {\n // Seek to the specified time (convert ms to seconds)\n video.currentTime = time / 1000;\n };\n video.onseeked = () => {\n try {\n const canvas = document.createElement('canvas');\n canvas.width = video.videoWidth;\n canvas.height = video.videoHeight;\n const ctx = canvas.getContext('2d');\n if (!ctx) {\n reject(new Error('Failed to get canvas context'));\n return;\n }\n ctx.drawImage(video, 0, 0, canvas.width, canvas.height);\n const dataUrl = canvas.toDataURL('image/jpeg', quality);\n resolve({\n uri: dataUrl,\n width: canvas.width,\n height: canvas.height,\n });\n }\n catch (error) {\n reject(new Error(`Failed to extract frame: ${error instanceof Error ? error.message : String(error)}`));\n }\n };\n video.onerror = () => {\n reject(new Error(`Failed to load video from ${sourceUri}`));\n };\n video.src = sourceUri;\n video.load();\n });\n }\n async getPluginVers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