-
Notifications
You must be signed in to change notification settings - Fork 23
/
mediaplayer.js
29 lines (24 loc) · 1007 Bytes
/
mediaplayer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const Bluez = require('..');
const bluetooth = new Bluez();
// This will only work if you already have a phone or other media
// player paired and already connected to your computer, of course. For Linux,
// checkout bluealsa as a very easy solution.
// Register callback for new Media players
bluetooth.on('mediaplayer', async (device, props) => {
var address = 'invalid';
console.log("[NEW] Mediaplayer:", device);
const player = await bluetooth.getMediaPlayer(device).catch(console.error);
player.on("PropertiesChanged", (props, invalidated) => {
console.log("[CHG] MediaPlayer:", device, props, invalidated);
});
player.on("interface-removed", () => {
console.log('[DEL] Player removed', device);
player.removeAllListeners();
delete mediaPlayers[address];
delete player;
})
});
bluetooth.init().then(async () => {
// listen on first bluetooth adapter
const adapter = await bluetooth.getAdapter();
}).catch(console.error);