@next2d/media 2.13.0 → 3.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/README.md CHANGED
@@ -1,11 +1,355 @@
1
- @next2d/renderer
2
- =============
1
+ # @next2d/media
3
2
 
4
- ## Installation
3
+ ## Overview / 概要
5
4
 
5
+ The `@next2d/media` package provides audio and video playback management using Web Audio API and HTML5 Video. This package enables Flash-like multimedia experiences in modern web applications.
6
+
7
+ `@next2d/media` パッケージは、Web Audio API と HTML5 Video を使用した音声および動画の再生管理を提供します。このパッケージにより、モダンなWebアプリケーションでFlashのようなマルチメディア体験を実現できます。
8
+
9
+ ## Features / 機能
10
+
11
+ - **Sound Playback**: MP3/audio file loading and playback with Web Audio API / Web Audio APIを使用したMP3/音声ファイルの読み込みと再生
12
+ - **Video Playback**: HTML5 video element integration with custom rendering pipeline / HTML5動画要素の統合とカスタムレンダリングパイプライン
13
+ - **Global Audio Control**: Application-wide volume and playback management / アプリケーション全体の音量と再生管理
14
+ - **Sound Transform**: Volume and loop control for individual sounds / 個別のサウンドの音量とループ制御
15
+
16
+ ## Installation / インストール
17
+
18
+ ```bash
19
+ npm install @next2d/media
20
+ ```
21
+
22
+ ## Directory Structure / ディレクトリ構造
23
+
24
+ ```
25
+ src/
26
+ ├── Sound.ts # Sound class for audio playback / 音声再生用のSoundクラス
27
+ ├── Sound/
28
+ │ ├── service/ # Sound-related services / Sound関連のサービス
29
+ │ │ ├── SoundDecodeService.ts # ArrayBuffer to AudioBuffer decoding / ArrayBufferからAudioBufferへのデコード
30
+ │ │ ├── SoundEndedEventService.ts # Sound ended event handling / サウンド終了イベント処理
31
+ │ │ ├── SoundLoadStartEventService.ts # Load start event / 読み込み開始イベント
32
+ │ │ └── SoundProgressEventService.ts # Load progress event / 読み込み進捗イベント
33
+ │ └── usecase/ # Sound use cases / Soundユースケース
34
+ │ ├── SoundBuildFromCharacterUseCase.ts # Build from character data / キャラクターデータからの構築
35
+ │ ├── SoundLoadEndEventUseCase.ts # Load completion handling / 読み込み完了処理
36
+ │ └── SoundLoadUseCase.ts # External sound loading / 外部サウンドの読み込み
37
+
38
+ ├── SoundMixer.ts # Global sound controller / グローバルサウンドコントローラー
39
+ ├── SoundMixer/
40
+ │ └── service/ # SoundMixer services / SoundMixerサービス
41
+ │ ├── SoundMixerStopAllService.ts # Stop all sounds / 全サウンド停止
42
+ │ └── SoundMixerUpdateVolumeService.ts # Update global volume / グローバル音量更新
43
+
44
+ ├── SoundTransform.ts # Volume and loop properties / 音量とループのプロパティ
45
+
46
+ ├── Video.ts # Video class for video playback / 動画再生用のVideoクラス
47
+ ├── Video/
48
+ │ ├── service/ # Video-related services / Video関連のサービス
49
+ │ │ ├── VideoApplyChangesService.ts # Apply video state changes / 動画状態変更の適用
50
+ │ │ ├── VideoCreateElementService.ts # Create video element / 動画要素の作成
51
+ │ │ ├── VideoEndedEventService.ts # Video ended event / 動画終了イベント
52
+ │ │ ├── VideoLoadedmetadataEventService.ts # Metadata loaded event / メタデータ読み込みイベント
53
+ │ │ └── VideoProgressEventService.ts # Video progress event / 動画進捗イベント
54
+ │ └── usecase/ # Video use cases / Videoユースケース
55
+ │ ├── VideoBuildFromCharacterUseCase.ts # Build from character / キャラクターからの構築
56
+ │ ├── VideoCanplaythroughEventUseCase.ts # Can play through event / 再生可能イベント
57
+ │ ├── VideoPlayEventUseCase.ts # Play event handling / 再生イベント処理
58
+ │ └── VideoRegisterEventUseCase.ts # Register video events / 動画イベント登録
59
+
60
+ ├── MediaUtil.ts # Utility functions for media / メディア用ユーティリティ関数
61
+ │ # - AudioContext management / AudioContext管理
62
+ │ # - Volume control / 音量制御
63
+ │ # - Playing sounds/videos tracking / 再生中サウンド/動画の追跡
64
+ │ # - AJAX helper / AJAXヘルパー
65
+
66
+ └── interface/ # TypeScript interfaces / TypeScript インターフェース
67
+ ├── ISoundCharacter.ts # Sound character definition / サウンドキャラクター定義
68
+ ├── IVideoCharacter.ts # Video character definition / 動画キャラクター定義
69
+ ├── IAjaxOption.ts # AJAX options / AJAXオプション
70
+ ├── IAjaxEvent.ts # AJAX events / AJAXイベント
71
+ ├── IURLRequestMethod.ts # URL request methods / URLリクエストメソッド
72
+ ├── IURLRequestHeader.ts # URL request headers / URLリクエストヘッダー
73
+ ├── IURLLoaderDataFormat.ts # URL loader data format / URLローダーデータフォーマット
74
+ ├── IBlendMode.ts # Blend mode types / ブレンドモード型
75
+ ├── IBounds.ts # Bounds interface / バウンズインターフェース
76
+ ├── ICharacter.ts # Character interface / キャラクターインターフェース
77
+ ├── IDictionaryTag.ts # Dictionary tag interface / 辞書タグインターフェース
78
+ ├── IFilterArray.ts # Filter array interface / フィルター配列インターフェース
79
+ ├── IGrid.ts # Grid interface / グリッドインターフェース
80
+ ├── ILoopConfig.ts # Loop config interface / ループ設定インターフェース
81
+ ├── ILoopType.ts # Loop type interface / ループタイプインターフェース
82
+ ├── IMovieClipActionObject.ts # MovieClip action object / MovieClipアクションオブジェクト
83
+ ├── IMovieClipCharacter.ts # MovieClip character / MovieClipキャラクター
84
+ ├── IMovieClipLabelObject.ts # MovieClip label object / MovieClipラベルオブジェクト
85
+ ├── IMovieClipSoundObject.ts # MovieClip sound object / MovieClipサウンドオブジェクト
86
+ ├── IPlaceObject.ts # Place object interface / 配置オブジェクトインターフェース
87
+ ├── IShapeCharacter.ts # Shape character / Shapeキャラクター
88
+ ├── ISoundTag.ts # Sound tag interface / サウンドタグインターフェース
89
+ ├── ISurfaceFilter.ts # Surface filter interface / サーフェスフィルターインターフェース
90
+ ├── ITextFieldCharacter.ts # TextField character / TextFieldキャラクター
91
+ ├── ITextFieldType.ts # TextField type / TextFieldタイプ
92
+ └── ITextFormatAlign.ts # TextFormat align / TextFormat配置
93
+ ```
94
+
95
+ ## API Overview / API概要
96
+
97
+ ### Sound Class / Soundクラス
98
+
99
+ ```typescript
100
+ import { Sound } from "@next2d/media";
101
+ import { URLRequest } from "@next2d/net";
102
+
103
+ const sound = new Sound();
104
+ sound.volume = 0.8;
105
+ sound.loopCount = 3; // Loop 3 times / 3回ループ
106
+
107
+ // Load external MP3 / 外部MP3を読み込み
108
+ await sound.load(new URLRequest("path/to/audio.mp3"));
109
+
110
+ // Play sound / サウンドを再生
111
+ sound.play();
112
+
113
+ // Stop sound / サウンドを停止
114
+ sound.stop();
115
+ ```
116
+
117
+ ### SoundMixer Class / SoundMixerクラス
118
+
119
+ ```typescript
120
+ import { SoundMixer } from "@next2d/media";
121
+
122
+ // Global volume control (0.0 - 1.0) / グローバル音量制御 (0.0 - 1.0)
123
+ SoundMixer.volume = 0.5;
124
+
125
+ // Stop all playing sounds and videos / 全ての再生中サウンドと動画を停止
126
+ SoundMixer.stopAll();
127
+ ```
128
+
129
+ ### Video Class / Videoクラス
130
+
131
+ ```typescript
132
+ import { Video } from "@next2d/media";
133
+
134
+ const video = new Video(640, 480);
135
+ video.smoothing = true;
136
+ video.loop = true;
137
+ video.autoPlay = true;
138
+ video.volume = 0.8;
139
+
140
+ // Set video source / 動画ソースを設定
141
+ video.src = "path/to/video.mp4";
142
+
143
+ // Play video / 動画を再生
144
+ await video.play();
145
+
146
+ // Pause video / 動画を一時停止
147
+ video.pause();
148
+
149
+ // Seek to position / 位置をシーク
150
+ video.seek(5.0); // Seek to 5 seconds / 5秒の位置にシーク
6
151
  ```
7
- npm install @next2d/renderer
152
+
153
+ ### SoundTransform Class / SoundTransformクラス
154
+
155
+ ```typescript
156
+ import { SoundTransform } from "@next2d/media";
157
+
158
+ const transform = new SoundTransform(0.8, 2);
159
+ // volume: 0.8, loopCount: 2
8
160
  ```
9
161
 
162
+ ## Sound Loading and Playback Flow / サウンド読み込みと再生フロー
163
+
164
+ ```mermaid
165
+ sequenceDiagram
166
+ participant User
167
+ participant Sound
168
+ participant SoundLoadUseCase
169
+ participant MediaUtil
170
+ participant SoundLoadEndEventUseCase
171
+ participant SoundDecodeService
172
+ participant AudioContext
173
+
174
+ User->>Sound: load(request)
175
+ Sound->>SoundLoadUseCase: execute(sound, request)
176
+ SoundLoadUseCase->>MediaUtil: $ajax(options)
177
+ MediaUtil->>MediaUtil: XMLHttpRequest
178
+
179
+ Note over MediaUtil: loadstart event
180
+ MediaUtil-->>Sound: SoundLoadStartEventService
181
+
182
+ Note over MediaUtil: progress event
183
+ MediaUtil-->>Sound: SoundProgressEventService
184
+
185
+ Note over MediaUtil: loadend event
186
+ MediaUtil->>SoundLoadEndEventUseCase: execute(sound, event)
187
+ SoundLoadEndEventUseCase->>SoundDecodeService: execute(arrayBuffer)
188
+ SoundDecodeService->>AudioContext: decodeAudioData(arrayBuffer)
189
+ AudioContext-->>SoundDecodeService: AudioBuffer
190
+ SoundDecodeService-->>SoundLoadEndEventUseCase: AudioBuffer
191
+ SoundLoadEndEventUseCase->>Sound: audioBuffer = result
192
+ SoundLoadEndEventUseCase-->>Sound: Dispatch COMPLETE event
193
+ Sound-->>User: Load completed
194
+
195
+ User->>Sound: play(startTime)
196
+ Sound->>MediaUtil: $getAudioContext()
197
+ MediaUtil-->>Sound: AudioContext
198
+ Sound->>AudioContext: createGain()
199
+ AudioContext-->>Sound: GainNode
200
+ Sound->>AudioContext: createBufferSource()
201
+ AudioContext-->>Sound: AudioBufferSourceNode
202
+ Sound->>Sound: Setup source & gain
203
+ Sound->>AudioBufferSourceNode: start(startTime)
204
+
205
+ Note over AudioBufferSourceNode: Playback in progress
206
+
207
+ AudioBufferSourceNode-->>Sound: ended event
208
+ Sound->>Sound: SoundEndedEventService
209
+
210
+ alt canLoop is true
211
+ Sound->>Sound: play() again
212
+ else
213
+ Sound->>Sound: stop()
214
+ end
215
+ ```
216
+
217
+ ## Video Rendering Pipeline / 動画レンダリングパイプライン
218
+
219
+ ```mermaid
220
+ sequenceDiagram
221
+ participant User
222
+ participant Video
223
+ participant VideoCreateElementService
224
+ participant VideoRegisterEventUseCase
225
+ participant HTMLVideoElement
226
+ participant VideoPlayEventUseCase
227
+ participant OffscreenCanvas
228
+ participant VideoApplyChangesService
229
+
230
+ User->>Video: new Video(width, height)
231
+ User->>Video: src = "video.mp4"
232
+ Video->>VideoCreateElementService: execute()
233
+ VideoCreateElementService-->>Video: HTMLVideoElement
234
+ Video->>VideoRegisterEventUseCase: execute(videoElement, video)
235
+
236
+ VideoRegisterEventUseCase->>HTMLVideoElement: addEventListener("loadedmetadata")
237
+ VideoRegisterEventUseCase->>HTMLVideoElement: addEventListener("canplaythrough")
238
+ VideoRegisterEventUseCase->>HTMLVideoElement: addEventListener("progress")
239
+ VideoRegisterEventUseCase->>HTMLVideoElement: addEventListener("ended")
240
+
241
+ Video->>HTMLVideoElement: src = url
242
+ Video->>HTMLVideoElement: load()
243
+
244
+ HTMLVideoElement-->>Video: loadedmetadata event
245
+ Note over Video: VideoLoadedmetadataEventService
246
+ Video->>Video: Create OffscreenCanvas
247
+ Video->>Video: Get 2D context
248
+ Video->>Video: loaded = true
249
+
250
+ HTMLVideoElement-->>Video: canplaythrough event
251
+ Note over Video: VideoCanplaythroughEventUseCase
252
+
253
+ alt autoPlay is true
254
+ Video->>Video: play()
255
+ end
256
+
257
+ User->>Video: play()
258
+ Video->>HTMLVideoElement: play()
259
+ Video->>VideoPlayEventUseCase: execute(video)
260
+
261
+ loop Animation frame loop
262
+ VideoPlayEventUseCase->>VideoPlayEventUseCase: requestAnimationFrame
263
+ VideoPlayEventUseCase->>VideoApplyChangesService: execute(video)
264
+ VideoApplyChangesService->>Video: Update currentTime
265
+ VideoApplyChangesService-->>Video: Dispatch UPDATE event
266
+ VideoPlayEventUseCase->>OffscreenCanvas: drawImage(videoElement)
267
+ Note over OffscreenCanvas: Render current frame
268
+ end
269
+
270
+ HTMLVideoElement-->>Video: ended event
271
+ Note over Video: VideoEndedEventService
272
+ Video-->>Video: Dispatch ENDED event
273
+
274
+ alt loop is true
275
+ Video->>Video: currentTime = 0
276
+ Video->>Video: play()
277
+ else
278
+ Video->>Video: ended = true
279
+ Video->>Video: pause()
280
+ end
281
+
282
+ User->>Video: pause()
283
+ Video->>HTMLVideoElement: pause()
284
+ Video->>VideoPlayEventUseCase: cancelAnimationFrame
285
+ Video-->>Video: Dispatch PAUSE event
286
+ ```
287
+
288
+ ## Key Components / 主要コンポーネント
289
+
290
+ ### MediaUtil.ts
291
+
292
+ Provides core utility functions for media handling:
293
+ メディア処理のためのコアユーティリティ関数を提供します:
294
+
295
+ - **AudioContext Management / AudioContext管理**: `$getAudioContext()`, `$bootAudioContext()`
296
+ - **Volume Control / 音量制御**: `$getVolume()`, `$setVolume()`
297
+ - **Playing Media Tracking / 再生中メディア追跡**: `$getPlayingSounds()`, `$getPlayingVideos()`
298
+ - **AJAX Helper / AJAXヘルパー**: `$ajax()` for loading external resources / 外部リソース読み込み用
299
+ - **Utility Functions / ユーティリティ関数**: `$clamp()` for value range limiting / 値の範囲制限用
300
+
301
+ ### Service Layer / サービス層
302
+
303
+ Services handle specific operations and events:
304
+ サービスは特定の操作とイベントを処理します:
305
+
306
+ - **Sound Services**: Decoding, event handling (loadstart, progress, ended)
307
+ - **Soundサービス**: デコード、イベント処理 (loadstart, progress, ended)
308
+ - **SoundMixer Services**: Global volume updates, stop all functionality
309
+ - **SoundMixerサービス**: グローバル音量更新、全停止機能
310
+ - **Video Services**: Element creation, state changes, event handling
311
+ - **Videoサービス**: 要素作成、状態変更、イベント処理
312
+
313
+ ### Use Case Layer / ユースケース層
314
+
315
+ Use cases orchestrate complex workflows:
316
+ ユースケースは複雑なワークフローを調整します:
317
+
318
+ - **Sound Use Cases**: Loading external audio, building from character data, load completion
319
+ - **Soundユースケース**: 外部音声読み込み、キャラクターデータからの構築、読み込み完了
320
+ - **Video Use Cases**: Event registration, playback management, character building
321
+ - **Videoユースケース**: イベント登録、再生管理、キャラクター構築
322
+
323
+ ## Architecture / アーキテクチャ
324
+
325
+ This package follows a clean architecture pattern:
326
+ このパッケージはクリーンアーキテクチャパターンに従っています:
327
+
328
+ 1. **Domain Layer**: Core classes (`Sound`, `Video`, `SoundMixer`, `SoundTransform`)
329
+ - **ドメイン層**: コアクラス (`Sound`, `Video`, `SoundMixer`, `SoundTransform`)
330
+
331
+ 2. **Use Case Layer**: Business logic orchestration (`usecase/` folders)
332
+ - **ユースケース層**: ビジネスロジックの調整 (`usecase/` フォルダ)
333
+
334
+ 3. **Service Layer**: Specific operations and event handling (`service/` folders)
335
+ - **サービス層**: 特定の操作とイベント処理 (`service/` フォルダ)
336
+
337
+ 4. **Utility Layer**: Shared utilities (`MediaUtil.ts`)
338
+ - **ユーティリティ層**: 共有ユーティリティ (`MediaUtil.ts`)
339
+
340
+ 5. **Interface Layer**: TypeScript type definitions (`interface/` folder)
341
+ - **インターフェース層**: TypeScript型定義 (`interface/` フォルダ)
342
+
343
+ ## Browser Compatibility / ブラウザ互換性
344
+
345
+ This package requires:
346
+ このパッケージには以下が必要です:
347
+
348
+ - Web Audio API support / Web Audio APIサポート
349
+ - HTML5 Video support / HTML5 Videoサポート
350
+ - OffscreenCanvas support (for Video) / OffscreenCanvasサポート (Video用)
351
+ - XMLHttpRequest / ArrayBuffer support / XMLHttpRequest / ArrayBufferサポート
352
+
10
353
  ## License
354
+
11
355
  This project is licensed under the [MIT License](https://opensource.org/licenses/MIT) - see the [LICENSE](LICENSE) file for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next2d/media",
3
- "version": "2.13.0",
3
+ "version": "3.0.0",
4
4
  "description": "Next2D Media Package",
5
5
  "author": "Toshiyuki Ienaga<ienaga@next2d.app> (https://github.com/ienaga/)",
6
6
  "license": "MIT",
@@ -24,9 +24,9 @@
24
24
  "url": "git+https://github.com/Next2D/Player.git"
25
25
  },
26
26
  "dependencies": {
27
- "@next2d/events": "2.13.0",
28
- "@next2d/net": "2.13.0",
29
- "@next2d/display": "2.13.0",
30
- "@next2d/geom": "2.13.0"
27
+ "@next2d/events": "3.0.0",
28
+ "@next2d/net": "3.0.0",
29
+ "@next2d/display": "3.0.0",
30
+ "@next2d/geom": "3.0.0"
31
31
  }
32
32
  }
@@ -22,9 +22,6 @@ export const execute = (video) => {
22
22
  if (playingVideos.indexOf(video) === -1) {
23
23
  playingVideos.push(video);
24
24
  }
25
- if (video.$context && video.$videoElement) {
26
- video.$context.drawImage(video.$videoElement, 0, 0, video.videoWidth, video.videoHeight);
27
- }
28
25
  return requestAnimationFrame(() => {
29
26
  execute(video);
30
27
  });