Skip to content

Commit 98d583b

Browse files
committed
Setup prettier
TODO, maybe add a pre-commit hook calling `npx prettier . --write`.
1 parent 8a13406 commit 98d583b

File tree

7 files changed

+64
-61
lines changed

7 files changed

+64
-61
lines changed

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore artifacts:
2+
public

.prettierrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22

33
<br>
44

5-
Simple video player demo made with WebCodecs / AudioWorklet. (No HTML5 videos!)
5+
Simple video player demo made with WebCodecs / AudioWorklet. (No HTML5 videos!)
66

7-
Visit https://webvideo-js.pages.dev/ to see the live demo.
7+
Visit https://webvideo-js.pages.dev/ to see the live demo.
88

9-
Currently, Chrome 94+ is required. (Tested for Chrome 99 on Linux)
9+
Currently, Chrome 94+ is required. (Tested for Chrome 99 on Linux)
1010

11-
To test locally, execute `npm install && npm run publish && node server.js`.
11+
To test locally, execute `npm install && npm run publish && node server.js`.
1212

1313
## Attributions for videos
1414

15-
* [Tears of Steel](https://mango.blender.org/) by Blender Foundation [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/)
15+
- [Tears of Steel](https://mango.blender.org/) by Blender Foundation [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/)
1616

17-
* [Elephants Dream](https://orange.blender.org/) by Blender Foundation [CC BY](https://orange.blender.org/blog/creative-commons-license-2/)
17+
- [Elephants Dream](https://orange.blender.org/) by Blender Foundation [CC BY](https://orange.blender.org/blog/creative-commons-license-2/)
1818

1919
## License
2020

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"esbuild": "^0.12.14",
2020
"eslint": "^7.29.0",
2121
"express": "^4.17.3",
22-
"prettier": "^2.3.2",
22+
"prettier": "2.8.8",
2323
"serve-index": "^1.9.1",
2424
"typescript": "^4.3.5"
2525
},

src/index.ts

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { WVPlayStateKind } from './core/state';
44
let player: WVPlayer | undefined;
55

66
// TODO: We can't rely on AAC-encoded assets here. opus and flac should work though.
7-
let movies:datatype[][] = [
8-
["./assets/TearsOfSteel.mp4", "[Excerpt] “Tears of Steel” by Blender Foundation (CC BY 3.0)"],
9-
["./assets/ElephantsDream.mp4", "[Excerpt] “Elephants Dream” by Blender Foundation (CC BY)"]
7+
let movies: datatype[][] = [
8+
['./assets/TearsOfSteel.mp4', '[Excerpt] “Tears of Steel” by Blender Foundation (CC BY 3.0)'],
9+
['./assets/ElephantsDream.mp4', '[Excerpt] “Elephants Dream” by Blender Foundation (CC BY)'],
1010
];
1111

1212
enum PlayBtnIcon {
@@ -46,7 +46,7 @@ window.addEventListener('beforeunload', (e) => {
4646

4747
if (player?.loadCalled()) {
4848
player?.unload();
49-
// blockingSleep(1000);
49+
// blockingSleep(1000);
5050
}
5151

5252
e.preventDefault();
@@ -65,17 +65,16 @@ window.addEventListener('load', async () => {
6565
let videoIndex = 0;
6666

6767
player = new WVPlayer({
68-
canvasElem: document.querySelector('#monitor') as HTMLCanvasElement,
69-
});
68+
canvasElem: document.querySelector('#monitor') as HTMLCanvasElement,
69+
});
7070
player.onEOS = async () => {
7171
videoIndex++;
7272
await advance();
73-
}
73+
};
7474

7575
setPlayBtnIcon(PlayBtnIcon.FONTAWESOME_PLAY, playBtnElem);
7676

7777
playBtnElem.addEventListener('click', async () => {
78-
7978
switch (player.playState()) {
8079
case WVPlayStateKind.PAUSED: {
8180
if (player.canPlay()) {
@@ -95,34 +94,32 @@ window.addEventListener('load', async () => {
9594
await advance();
9695
}
9796
}
98-
9997
});
10098

10199
skipElem.addEventListener('click', async () => {
102-
await advance();
100+
await advance();
103101
});
104102

105-
async function advance() {
106-
if (videoIndex >= videoCount)
107-
videoIndex = 0;
108-
const url = new URL(movies[videoIndex][0], location.origin).href;
109-
await player.setUrl(url, {
110-
onStart: async () => {
111-
hidePlayBtn(playBtnWrapperElem);
112-
showLoader(loaderElem);
113-
},
114-
onEnd: async () => {
115-
hideLoader(loaderElem);
116-
showPlayBtn(playBtnWrapperElem);
117-
autohidePlayBtn(false, playBtnWrapperElem);
118-
setPlayBtnIcon(PlayBtnIcon.FONTAWESOME_PLAY, playBtnElem);
119-
},
120-
});
121-
await player.play();
122-
autohidePlayBtn(true, playBtnWrapperElem);
123-
setPlayBtnIcon(PlayBtnIcon.FONTAWESOME_PAUSE, playBtnElem);
124-
playTitleElem.textContent = movies[videoIndex][1];
125-
}
103+
async function advance() {
104+
if (videoIndex >= videoCount) videoIndex = 0;
105+
const url = new URL(movies[videoIndex][0], location.origin).href;
106+
await player.setUrl(url, {
107+
onStart: async () => {
108+
hidePlayBtn(playBtnWrapperElem);
109+
showLoader(loaderElem);
110+
},
111+
onEnd: async () => {
112+
hideLoader(loaderElem);
113+
showPlayBtn(playBtnWrapperElem);
114+
autohidePlayBtn(false, playBtnWrapperElem);
115+
setPlayBtnIcon(PlayBtnIcon.FONTAWESOME_PLAY, playBtnElem);
116+
},
117+
});
118+
await player.play();
119+
autohidePlayBtn(true, playBtnWrapperElem);
120+
setPlayBtnIcon(PlayBtnIcon.FONTAWESOME_PAUSE, playBtnElem);
121+
playTitleElem.textContent = movies[videoIndex][1];
122+
}
126123

127124
await advance();
128125
});

src/media/format/demuxerMP4Box.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function createWVMediaStreamInfo(
112112
width: (track as MP4Box.MP4VideoTrack).video.width,
113113
height: (track as MP4Box.MP4VideoTrack).video.height,
114114
};
115-
if (track.codec.startsWith("avc")) {
115+
if (track.codec.startsWith('avc')) {
116116
video.avcDescription = createAVCDescription(trackIdx, file);
117117
}
118118
} else if (streamType === 'audio') {

src/player/player.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,28 @@ export class WVPlayer {
5151
logger.setLevel(this.#shared.loglevel);
5252
}
5353

54-
async setUrl(url: string, cb?: { onStart?: () => Promise<void>; onEnd?: () => Promise<void> }): Promise<void> {
55-
await this.unload();
56-
this.#shared.videoUrl = url;
57-
return this.load(cb);
58-
}
54+
async setUrl(
55+
url: string,
56+
cb?: { onStart?: () => Promise<void>; onEnd?: () => Promise<void> }
57+
): Promise<void> {
58+
await this.unload();
59+
this.#shared.videoUrl = url;
60+
return this.load(cb);
61+
}
5962

6063
async load(cb?: { onStart?: () => Promise<void>; onEnd?: () => Promise<void> }): Promise<void> {
6164
if (this.#isLoadCalled) {
6265
throw Error('load() is already called');
6366
}
6467
this.#isLoadCalled = true;
6568

66-
this.#shared.videoDecoderShouldBeDead.store(false);
67-
this.#shared.audioDecoderShouldBeDead.store(false);
69+
this.#shared.videoDecoderShouldBeDead.store(false);
70+
this.#shared.audioDecoderShouldBeDead.store(false);
6871

69-
this.#videoDecoder = new WVVideoDecoderWorkerFront({
70-
maxVideoFrameLength: this.#maxVideoFrameLength,
71-
});
72-
this.#audioDecoder = new WVAudioDecoderWorkerFront();
72+
this.#videoDecoder = new WVVideoDecoderWorkerFront({
73+
maxVideoFrameLength: this.#maxVideoFrameLength,
74+
});
75+
this.#audioDecoder = new WVAudioDecoderWorkerFront();
7376

7477
this.#shared.playState.store(WVPlayStateKind.BUFFERING);
7578
await cb?.onStart?.();
@@ -111,7 +114,7 @@ export class WVPlayer {
111114

112115
async unload(cb?: { onStart?: () => Promise<void>; onEnd?: () => Promise<void> }): Promise<void> {
113116
if (!this.#isLoadCalled) {
114-
return;
117+
return;
115118
}
116119
this.#isLoadCalled = false;
117120

@@ -123,10 +126,10 @@ export class WVPlayer {
123126

124127
await this.#videoDecoder.uninit(this.#shared);
125128
await this.#audioDecoder.uninit(this.#shared);
126-
this.#shared.videoBufferFull.store(false);
127-
this.#shared.audioBufferFull.store(false);
128-
this.#videoDecoder = null;
129-
this.#audioDecoder = null;
129+
this.#shared.videoBufferFull.store(false);
130+
this.#shared.audioBufferFull.store(false);
131+
this.#videoDecoder = null;
132+
this.#audioDecoder = null;
130133
}
131134
await cb?.onEnd?.();
132135
}
@@ -177,10 +180,10 @@ export class WVPlayer {
177180
this.#videoDecoder.pop(this.#shared);
178181
}
179182

180-
if (currentTime >= this.length()) {
181-
await this.pause();
182-
await this.onEOS();
183-
}
183+
if (currentTime >= this.length()) {
184+
await this.pause();
185+
await this.onEOS();
186+
}
184187
requestAnimationFrame(this.mainLoop.bind(this));
185188
}
186189

@@ -191,10 +194,10 @@ export class WVPlayer {
191194
return this.#videoStream.timescale;
192195
}
193196
length(): number {
194-
return this.#videoStream.duration / this.#videoStream.timescale;
197+
return this.#videoStream.duration / this.#videoStream.timescale;
195198
}
196199
lengthMS(): number {
197-
return this.#videoStream.duration / this.#videoStream.timescale * 1000;
200+
return (this.#videoStream.duration / this.#videoStream.timescale) * 1000;
198201
}
199202
bitrate(): number {
200203
return this.#videoStream.bitrate;

0 commit comments

Comments
 (0)