@scarlett-player/native 0.1.2 → 0.4.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Hackney Enterprises Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs CHANGED
@@ -25,15 +25,26 @@ __export(index_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(index_exports);
27
27
  var import_core = require("@scarlett-player/core");
28
- var SUPPORTED_EXTENSIONS = ["mp4", "webm", "mov", "mkv", "ogv", "ogg", "m4v"];
28
+ var VIDEO_EXTENSIONS = ["mp4", "webm", "mov", "mkv", "ogv", "m4v"];
29
+ var AUDIO_EXTENSIONS = ["mp3", "wav", "ogg", "flac", "aac", "m4a", "opus", "weba"];
30
+ var SUPPORTED_EXTENSIONS = [...VIDEO_EXTENSIONS, ...AUDIO_EXTENSIONS];
29
31
  var MIME_TYPES = {
32
+ // Video
30
33
  mp4: "video/mp4",
31
34
  m4v: "video/mp4",
32
35
  webm: "video/webm",
33
36
  mov: "video/quicktime",
34
37
  mkv: "video/x-matroska",
35
38
  ogv: "video/ogg",
36
- ogg: "video/ogg"
39
+ // Audio
40
+ mp3: "audio/mpeg",
41
+ wav: "audio/wav",
42
+ ogg: "audio/ogg",
43
+ flac: "audio/flac",
44
+ aac: "audio/aac",
45
+ m4a: "audio/mp4",
46
+ opus: "audio/opus",
47
+ weba: "audio/webm"
37
48
  };
38
49
  function createNativePlugin(config) {
39
50
  const preload = config?.preload ?? "metadata";
@@ -54,9 +65,13 @@ function createNativePlugin(config) {
54
65
  const getMimeType = (ext) => {
55
66
  return MIME_TYPES[ext] || "video/mp4";
56
67
  };
68
+ const isAudioExtension = (ext) => {
69
+ return AUDIO_EXTENSIONS.includes(ext);
70
+ };
57
71
  const canBrowserPlay = (mimeType) => {
58
- const testVideo = document.createElement("video");
59
- const canPlay = testVideo.canPlayType(mimeType);
72
+ const isAudio = mimeType.startsWith("audio/");
73
+ const testElement = isAudio ? document.createElement("audio") : document.createElement("video");
74
+ const canPlay = testElement.canPlayType(mimeType);
60
75
  return canPlay === "probably" || canPlay === "maybe";
61
76
  };
62
77
  const getOrCreateVideo = () => {
@@ -67,10 +82,14 @@ function createNativePlugin(config) {
67
82
  return video;
68
83
  }
69
84
  video = document.createElement("video");
70
- video.style.cssText = "width:100%;height:100%;display:block;object-fit:contain;background:#000";
85
+ video.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;display:block;object-fit:contain;background:#000";
71
86
  video.preload = preload;
72
87
  video.controls = false;
73
88
  video.playsInline = true;
89
+ const poster = api?.getState("poster");
90
+ if (poster) {
91
+ video.poster = poster;
92
+ }
74
93
  api?.container.appendChild(video);
75
94
  return video;
76
95
  };
@@ -186,10 +205,10 @@ function createNativePlugin(config) {
186
205
  };
187
206
  const plugin = {
188
207
  id: "native-provider",
189
- name: "Native Video Provider",
208
+ name: "Native Media Provider",
190
209
  version: "1.0.0",
191
210
  type: "provider",
192
- description: "Native HTML5 video playback for MP4, WebM, MOV, MKV",
211
+ description: "Native HTML5 playback for video (MP4, WebM, MOV) and audio (MP3, WAV, FLAC, AAC)",
193
212
  canPlay(src) {
194
213
  const ext = getExtension(src);
195
214
  if (!SUPPORTED_EXTENSIONS.includes(ext)) {
@@ -251,18 +270,44 @@ function createNativePlugin(config) {
251
270
  if (!api) throw new Error("Plugin not initialized");
252
271
  const ext = getExtension(src);
253
272
  const mimeType = getMimeType(ext);
254
- api.logger.info("Loading native video source", { src, mimeType });
273
+ const isAudio = isAudioExtension(ext);
274
+ api.logger.info("Loading native media source", { src, mimeType, isAudio });
255
275
  cleanup();
256
276
  api.setState("playbackState", "loading");
257
277
  api.setState("buffering", true);
278
+ api.setState("mediaType", isAudio ? "audio" : "video");
279
+ if (isAudio) {
280
+ try {
281
+ const url = new URL(src, window.location.href);
282
+ const filename = url.pathname.split("/").pop() || "Audio";
283
+ const title = decodeURIComponent(filename.replace(/\.[^.]+$/, "").replace(/[-_]/g, " "));
284
+ api.setState("title", title);
285
+ } catch {
286
+ api.setState("title", "Audio");
287
+ }
288
+ }
258
289
  api.setState("qualities", []);
259
290
  api.setState("currentQuality", null);
260
291
  const videoEl = getOrCreateVideo();
292
+ if (isAudio) {
293
+ videoEl.style.display = "none";
294
+ videoEl.poster = "";
295
+ } else {
296
+ videoEl.style.display = "block";
297
+ const poster = api.getState("poster");
298
+ if (poster) {
299
+ videoEl.poster = poster;
300
+ }
301
+ }
261
302
  cleanupEvents = setupEventListeners(videoEl);
262
303
  return new Promise((resolve, reject) => {
263
304
  const onLoaded = () => {
264
305
  videoEl.removeEventListener("loadedmetadata", onLoaded);
265
306
  videoEl.removeEventListener("error", onError);
307
+ const muted = api?.getState("muted");
308
+ const volume = api?.getState("volume");
309
+ if (muted !== void 0) videoEl.muted = muted;
310
+ if (volume !== void 0) videoEl.volume = volume;
266
311
  api?.setState("source", { src, type: mimeType });
267
312
  api?.setState("playbackState", "ready");
268
313
  api?.setState("buffering", false);
package/dist/index.d.cts CHANGED
@@ -1,14 +1,24 @@
1
1
  import { PluginType, IPluginAPI } from '@scarlett-player/core';
2
2
 
3
3
  /**
4
- * Native Video Provider Plugin for Scarlett Player
4
+ * Native Media Provider Plugin for Scarlett Player
5
5
  *
6
6
  * Provides playback for native browser-supported formats:
7
+ *
8
+ * Video:
7
9
  * - MP4 (H.264/AAC)
8
10
  * - WebM (VP8/VP9/Opus)
9
11
  * - MOV (H.264/AAC)
10
12
  * - MKV (varies by browser)
11
13
  * - OGG/OGV (Theora/Vorbis)
14
+ *
15
+ * Audio:
16
+ * - MP3 (MPEG Audio Layer 3)
17
+ * - WAV (Waveform Audio)
18
+ * - OGG (Vorbis)
19
+ * - FLAC (Free Lossless Audio Codec)
20
+ * - AAC (Advanced Audio Coding)
21
+ * - M4A (MPEG-4 Audio)
12
22
  */
13
23
 
14
24
  interface NativePluginConfig {
package/dist/index.d.ts CHANGED
@@ -1,14 +1,24 @@
1
1
  import { PluginType, IPluginAPI } from '@scarlett-player/core';
2
2
 
3
3
  /**
4
- * Native Video Provider Plugin for Scarlett Player
4
+ * Native Media Provider Plugin for Scarlett Player
5
5
  *
6
6
  * Provides playback for native browser-supported formats:
7
+ *
8
+ * Video:
7
9
  * - MP4 (H.264/AAC)
8
10
  * - WebM (VP8/VP9/Opus)
9
11
  * - MOV (H.264/AAC)
10
12
  * - MKV (varies by browser)
11
13
  * - OGG/OGV (Theora/Vorbis)
14
+ *
15
+ * Audio:
16
+ * - MP3 (MPEG Audio Layer 3)
17
+ * - WAV (Waveform Audio)
18
+ * - OGG (Vorbis)
19
+ * - FLAC (Free Lossless Audio Codec)
20
+ * - AAC (Advanced Audio Coding)
21
+ * - M4A (MPEG-4 Audio)
12
22
  */
13
23
 
14
24
  interface NativePluginConfig {
package/dist/index.js CHANGED
@@ -1,14 +1,25 @@
1
1
  // src/index.ts
2
2
  import { ErrorCode } from "@scarlett-player/core";
3
- var SUPPORTED_EXTENSIONS = ["mp4", "webm", "mov", "mkv", "ogv", "ogg", "m4v"];
3
+ var VIDEO_EXTENSIONS = ["mp4", "webm", "mov", "mkv", "ogv", "m4v"];
4
+ var AUDIO_EXTENSIONS = ["mp3", "wav", "ogg", "flac", "aac", "m4a", "opus", "weba"];
5
+ var SUPPORTED_EXTENSIONS = [...VIDEO_EXTENSIONS, ...AUDIO_EXTENSIONS];
4
6
  var MIME_TYPES = {
7
+ // Video
5
8
  mp4: "video/mp4",
6
9
  m4v: "video/mp4",
7
10
  webm: "video/webm",
8
11
  mov: "video/quicktime",
9
12
  mkv: "video/x-matroska",
10
13
  ogv: "video/ogg",
11
- ogg: "video/ogg"
14
+ // Audio
15
+ mp3: "audio/mpeg",
16
+ wav: "audio/wav",
17
+ ogg: "audio/ogg",
18
+ flac: "audio/flac",
19
+ aac: "audio/aac",
20
+ m4a: "audio/mp4",
21
+ opus: "audio/opus",
22
+ weba: "audio/webm"
12
23
  };
13
24
  function createNativePlugin(config) {
14
25
  const preload = config?.preload ?? "metadata";
@@ -29,9 +40,13 @@ function createNativePlugin(config) {
29
40
  const getMimeType = (ext) => {
30
41
  return MIME_TYPES[ext] || "video/mp4";
31
42
  };
43
+ const isAudioExtension = (ext) => {
44
+ return AUDIO_EXTENSIONS.includes(ext);
45
+ };
32
46
  const canBrowserPlay = (mimeType) => {
33
- const testVideo = document.createElement("video");
34
- const canPlay = testVideo.canPlayType(mimeType);
47
+ const isAudio = mimeType.startsWith("audio/");
48
+ const testElement = isAudio ? document.createElement("audio") : document.createElement("video");
49
+ const canPlay = testElement.canPlayType(mimeType);
35
50
  return canPlay === "probably" || canPlay === "maybe";
36
51
  };
37
52
  const getOrCreateVideo = () => {
@@ -42,10 +57,14 @@ function createNativePlugin(config) {
42
57
  return video;
43
58
  }
44
59
  video = document.createElement("video");
45
- video.style.cssText = "width:100%;height:100%;display:block;object-fit:contain;background:#000";
60
+ video.style.cssText = "position:absolute;top:0;left:0;width:100%;height:100%;display:block;object-fit:contain;background:#000";
46
61
  video.preload = preload;
47
62
  video.controls = false;
48
63
  video.playsInline = true;
64
+ const poster = api?.getState("poster");
65
+ if (poster) {
66
+ video.poster = poster;
67
+ }
49
68
  api?.container.appendChild(video);
50
69
  return video;
51
70
  };
@@ -161,10 +180,10 @@ function createNativePlugin(config) {
161
180
  };
162
181
  const plugin = {
163
182
  id: "native-provider",
164
- name: "Native Video Provider",
183
+ name: "Native Media Provider",
165
184
  version: "1.0.0",
166
185
  type: "provider",
167
- description: "Native HTML5 video playback for MP4, WebM, MOV, MKV",
186
+ description: "Native HTML5 playback for video (MP4, WebM, MOV) and audio (MP3, WAV, FLAC, AAC)",
168
187
  canPlay(src) {
169
188
  const ext = getExtension(src);
170
189
  if (!SUPPORTED_EXTENSIONS.includes(ext)) {
@@ -226,18 +245,44 @@ function createNativePlugin(config) {
226
245
  if (!api) throw new Error("Plugin not initialized");
227
246
  const ext = getExtension(src);
228
247
  const mimeType = getMimeType(ext);
229
- api.logger.info("Loading native video source", { src, mimeType });
248
+ const isAudio = isAudioExtension(ext);
249
+ api.logger.info("Loading native media source", { src, mimeType, isAudio });
230
250
  cleanup();
231
251
  api.setState("playbackState", "loading");
232
252
  api.setState("buffering", true);
253
+ api.setState("mediaType", isAudio ? "audio" : "video");
254
+ if (isAudio) {
255
+ try {
256
+ const url = new URL(src, window.location.href);
257
+ const filename = url.pathname.split("/").pop() || "Audio";
258
+ const title = decodeURIComponent(filename.replace(/\.[^.]+$/, "").replace(/[-_]/g, " "));
259
+ api.setState("title", title);
260
+ } catch {
261
+ api.setState("title", "Audio");
262
+ }
263
+ }
233
264
  api.setState("qualities", []);
234
265
  api.setState("currentQuality", null);
235
266
  const videoEl = getOrCreateVideo();
267
+ if (isAudio) {
268
+ videoEl.style.display = "none";
269
+ videoEl.poster = "";
270
+ } else {
271
+ videoEl.style.display = "block";
272
+ const poster = api.getState("poster");
273
+ if (poster) {
274
+ videoEl.poster = poster;
275
+ }
276
+ }
236
277
  cleanupEvents = setupEventListeners(videoEl);
237
278
  return new Promise((resolve, reject) => {
238
279
  const onLoaded = () => {
239
280
  videoEl.removeEventListener("loadedmetadata", onLoaded);
240
281
  videoEl.removeEventListener("error", onError);
282
+ const muted = api?.getState("muted");
283
+ const volume = api?.getState("volume");
284
+ if (muted !== void 0) videoEl.muted = muted;
285
+ if (volume !== void 0) videoEl.volume = volume;
241
286
  api?.setState("source", { src, type: mimeType });
242
287
  api?.setState("playbackState", "ready");
243
288
  api?.setState("buffering", false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scarlett-player/native",
3
- "version": "0.1.2",
3
+ "version": "0.4.0",
4
4
  "description": "Native Video Provider Plugin for Scarlett Player (MP4, WebM, MOV, MKV)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -16,20 +16,14 @@
16
16
  "files": [
17
17
  "dist"
18
18
  ],
19
- "scripts": {
20
- "build": "tsup src/index.ts --format esm,cjs --dts",
21
- "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
22
- "test": "vitest --run",
23
- "test:watch": "vitest"
24
- },
25
19
  "peerDependencies": {
26
- "@scarlett-player/core": "^0.1.0"
20
+ "@scarlett-player/core": "^0.4.0"
27
21
  },
28
22
  "devDependencies": {
29
- "@scarlett-player/core": "workspace:*",
30
23
  "typescript": "^5.3.0",
31
24
  "tsup": "^8.0.0",
32
- "vitest": "^1.6.0"
25
+ "vitest": "^1.6.0",
26
+ "@scarlett-player/core": "0.4.0"
33
27
  },
34
28
  "keywords": [
35
29
  "video",
@@ -49,5 +43,11 @@
49
43
  "bugs": {
50
44
  "url": "https://github.com/Hackney-Enterprises-Inc/scarlett-player/issues"
51
45
  },
52
- "homepage": "https://scarlettplayer.com"
53
- }
46
+ "homepage": "https://scarlettplayer.com",
47
+ "scripts": {
48
+ "build": "tsup src/index.ts --format esm,cjs --dts",
49
+ "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
50
+ "test": "vitest --run",
51
+ "test:watch": "vitest"
52
+ }
53
+ }