Skip to content

Commit 7d78b30

Browse files
committed
rc works
1 parent cdcf4d1 commit 7d78b30

File tree

5 files changed

+73
-84
lines changed

5 files changed

+73
-84
lines changed

.vscode/launch.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"skipFiles": [
1212
"<node_internals>/**"
1313
],
14-
"program": "${workspaceFolder}\\src\\index.js"
15-
}
14+
"program": "${workspaceFolder}/lib/index.mjs"
15+
},
16+
1617
]
1718
}

lib/index.mjs

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { spawn } from "node:child_process";
2+
import { setMaxIdleHTTPParsers } from "node:http";
3+
4+
const sleep = (time => new Promise(r => setTimeout(r, time)));
5+
6+
/**
7+
*
8+
*/
9+
export class VlcPlayer {
10+
11+
/**
12+
*
13+
*/
14+
constructor() {
15+
this._executable = "cvlc";
16+
if (process.platform === "win32") {
17+
this._executable = "vlc.exe"
18+
}
19+
}
20+
21+
/**
22+
* Opens the VLC media player and start playing the given file.
23+
*
24+
* @param {string=} filePath - The file to play.
25+
*/
26+
async open() {
27+
let options = [
28+
"--no-video-title-show",
29+
"-I", "rc"
30+
];
31+
this._vlc = spawn(this._executable, options);
32+
while (!this._vlc.pid) {
33+
await sleep(10);
34+
}
35+
this._vlc.stdout.on("data", data => {
36+
process.stdout.write(data);
37+
});
38+
this._vlc.stderr.on("data", data => {
39+
process.stderr.write(data);
40+
});
41+
this._rc = this._vlc.stdin;
42+
this._rc.write("playlist\n");
43+
}
44+
45+
play(filePath, repeat = false) {
46+
}
47+
48+
/**
49+
* Terminate the VLC process.
50+
*/
51+
async close() {
52+
this._rc.end("quit\n");
53+
this._vlc = undefined;
54+
this._rc = undefined;
55+
}
56+
}

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vlcplayer-node",
33
"version": "0.0.1",
44
"description": "A library for controlling VLC player on any system and OS including Raspberry PI.",
5-
"main": "src/index.js",
5+
"main": "lib/index.js",
66
"scripts": {
77
"test": "mocha --timeout 30000"
88
},
@@ -27,7 +27,6 @@
2727
},
2828
"homepage": "https://github.com/formix/vlcplayer-node#readme",
2929
"dependencies": {
30-
"telnet-client": "^2.0.8",
3130
"winston": "^3.8.2"
3231
},
3332
"devDependencies": {

src/index.mjs

-67
This file was deleted.

test/VlcPlayerTests.mjs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import assert from "assert";
2-
import {VlcPlayer} from "../src/index.mjs";
2+
import {VlcPlayer} from "./../lib/index.mjs"
33

44

55
describe("VlcPlayer", async () => {
66
describe("#open()", async () =>
77
it("Should start a new player with the given stream", async () => {
88
let player = new VlcPlayer();
9-
player.open("D:\\tests\\vlcplayer\\window-01-initial.mp4");
9+
await player.open();
1010
assert.equal(true, player._vlc.pid > 0);
1111
await sleep(2000);
12-
player.close();
12+
await player.close();
1313
}));
1414

15-
describe("#play()", async () =>
16-
it("Should start a new player whith a stream the play another one.", async () => {
17-
let player = new VlcPlayer();
18-
player.open("D:\\tests\\vlcplayer\\window-01-initial.mp4");
19-
assert.equal(true, player._vlc.pid > 0);
20-
await sleep(3000);
21-
player.play("D:\\tests\\vlcplayer\\window-02-storm-begin.mp4");
22-
await sleep(2000);
23-
player.close();
24-
}));
15+
// describe("#play()", async () =>
16+
// it("Should start a new player whith a stream the play another one.", async () => {
17+
// let player = new VlcPlayer();
18+
// player.open("D:\\tests\\vlcplayer\\window-01-initial.mp4");
19+
// assert.equal(true, player._vlc.pid > 0);
20+
// await sleep(3000);
21+
// player.play("D:\\tests\\vlcplayer\\window-02-storm-begin.mp4");
22+
// await sleep(2000);
23+
// player.close();
24+
// }));
2525
}
2626
);
2727

0 commit comments

Comments
 (0)