Skip to content

Commit 457afbe

Browse files
committed
Final test on RPI4
1 parent dd1ca99 commit 457afbe

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

lib/index.mjs

+16-23
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class VlcPlayer {
2020

2121
/**
2222
* Open the VLC media player with an empty playlist. VLC will not take
23-
* over the display until the first media is added to the playlist.
23+
* over the display until the first media is enqueueed to the playlist.
2424
*/
2525
async open() {
2626
return new Promise((resolve, reject) => {
@@ -38,13 +38,12 @@ export class VlcPlayer {
3838
if (this._verbose) {
3939
this._vlc.stderr.on("data", data => process.stderr.write(data));
4040
}
41-
this._writecmd = promisify(this._vlc.stdin.write);
4241
return resolve();
4342
});
4443
}
4544

4645
/**
47-
* Start playing after being paused or add the given file at the end of
46+
* Start playing after being paused or enqueue the given file at the end of
4847
* the playlist and start playing it. If the file is already in the
4948
* playlist, jump to that media position in the playlist instead.
5049
*
@@ -56,7 +55,7 @@ export class VlcPlayer {
5655
}
5756
else {
5857
if (!this._playlist.has(mediaPath)) {
59-
await this.add(mediaPath);
58+
await this.enqueue(mediaPath);
6059
}
6160
let index = this._playlist.get(mediaPath);
6261
await this.exec(`goto ${index}`);
@@ -71,25 +70,20 @@ export class VlcPlayer {
7170
}
7271

7372
/**
74-
* Add the specified media at the end of the playlist. Pause the media
75-
* if it is the first one.
73+
* Enqueue the specified media at the end of the playlist.
7674
*
7775
* @param {string} mediaPath The path of the media to play.
7876
*/
79-
async add(mediaPath) {
77+
async enqueue(mediaPath) {
8078
if (!fs.existsSync(mediaPath)) {
8179
throw new Error(`Media '${mediaPath}' not found.`);
8280
}
8381
if (this._playlist.has(mediaPath)) {
8482
throw new Error(`Media '${mediaPath}' already in the playlist.`);
8583
}
86-
let firstFile = this._playlistIndex === 3;
8784
this._playlist.set(mediaPath, this._playlistIndex);
8885
this._playlistIndex++;
89-
await this.exec(`add ${mediaPath}`);
90-
if (firstFile) {
91-
await this.exec("pause");
92-
}
86+
await this.exec(`enqueue ${mediaPath}`);
9387
}
9488

9589
/**
@@ -125,17 +119,16 @@ export class VlcPlayer {
125119
*
126120
* @param {string} command - The command to execute.
127121
*/
128-
async exec(command) {
129-
if (!command) {
130-
throw new Error("The command parameter must be provided.");
131-
}
132-
let retries = 0;
133-
let writeSuccess = false;
134-
while (!writeSuccess && retries < 10) {
135-
if (retries > 0) await _msleep(50);
136-
retries++;
137-
writeSuccess = await this._writecmd(`${command}\n`);
138-
}
122+
exec(command) {
123+
return new Promise((resolve, reject) => {
124+
if (!command) {
125+
return reject("The command parameter must be provided.");
126+
}
127+
this._vlc.stdin.write(`${command}\n`, err => {
128+
if (err) reject(err);
129+
return resolve();
130+
});
131+
});
139132
}
140133
}
141134

package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/IntegratedTests.mjs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { VlcPlayer, sleep } from "vlcplayer"
1+
import { VlcPlayer, sleep } from "../lib/index.mjs";
22

3-
let mediasHome = "/var/medias/";
3+
let mediasHome = "/var/xcape/videos/";
44
const VIDEOS = {
5-
BadWeather: `${mediasHome}2019_sc02_067_v001_BUFFER1-1080.mp4`, // 20 seconds
6-
Tornado: `${mediasHome}2019_sc02_067_v001_TRIGGER1-1080.mp4`, // 20 seconds
7-
Flying: `${mediasHome}2019_sc02_067_v001_BUFFER2-1080.mp4`, // 20 seconds
8-
FallDown: `${mediasHome}2019_sc02_067_v001_TRIGGER2-1080.mp4`, // 13 seconds
9-
CropField: `${mediasHome}2019_sc02_067_v001_BUFFER3-1080.mp4` // 20 seconds
5+
BadWeather: `${mediasHome}Wizard-of-Oz-Tornado-2019_sc02_067_v001_BUFFER1-1080.mp4`, // 20 seconds
6+
Tornado: `${mediasHome}Wizard-of-Oz-Tornado-2019_sc02_067_v001_TRIGGER1-1080.mp4`, // 20 seconds
7+
Flying: `${mediasHome}Wizard-of-Oz-Tornado-2019_sc02_067_v001_BUFFER2-1080.mp4`, // 20 seconds
8+
FallDown: `${mediasHome}Wizard-of-Oz-Tornado-2019_sc02_067_v001_TRIGGER2-1080.mp4`, // 13 seconds
9+
CropField: `${mediasHome}Wizard-of-Oz-Tornado-2019_sc02_067_v001_BUFFER3-1080.mp4` // 20 seconds
1010
};
1111

1212
let player = new VlcPlayer();
1313
await player.open();
1414
for (let key in VIDEOS) {
15-
await player.add(VIDEOS[key]);
15+
await player.enqueue(VIDEOS[key]);
1616
}
1717
await player.play(VIDEOS.BadWeather);
1818
await player.repeat("on");

0 commit comments

Comments
 (0)