Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mpris-service to handle mediakeys #38

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 78 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ var server = require('http').createServer(app);
var io = require('socket.io')(server);
var fs = require('fs');

var Player = require("mpris-service");
var player = Player({
name: "Patiobar",
identity: "Node.js pianobar controller",
supportedInterfaces: ["player"],
});

var fifo = process.env.PIANOBAR_FIFO || 'ctl';
var listenPort = process.env.PATIOBAR_PORT || 3000;

Expand All @@ -16,8 +23,23 @@ function readCurrentSong() {
var currentSong = fs.readFileSync(process.env.HOME + '/.config/pianobar/currentSong').toString()

if (currentSong) {
var a = currentSong.split(',,,');
io.emit('start', { artist: a[0], title: a[1], album: a[2], coverArt: a[3], rating: a[4], stationName: a[5] });
const a = currentSong.split(",,,");
io.emit("start", {
artist: a[0],
title: a[1],
album: a[2],
coverArt: a[3],
rating: a[4],
stationName: a[5],
});
player.metadata = {
"mpris:length": 0,
"mpris:artUrl": a[3],
"xesam:title": a[1],
"xesam:album": a[2],
"xesam:artist": [a[0]],
};
player.playbackStatus = "Playing";
}

}
Expand Down Expand Up @@ -102,3 +124,57 @@ app.post('/lovehate', function(request, response) {


});

// mpris events
const events = [
"raise",
"quit",
"next",
"previous",
"pause",
"playpause",
"stop",
"play",
"seek",
"position",
"open",
"volume",
"loopStatus",
"shuffle",
];
events.forEach(function (eventName) {
player.on(eventName, function () {
console.log("Event:", eventName, arguments);
switch (eventName) {
case "quit":
PidoraCTL("q");
process.exit();
break;
case "playpause":
PidoraCTL("p");
if (player.playbackStatus !== "Playing") {
player.playbackStatus = "Playing";
} else {
player.playbackStatus = "Paused";
}
break;
case "play":
PidoraCTL("P");
player.playbackStatus = "Playing";
break;
case "pause":
PidoraCTL("S");
player.playbackStatus = "Paused";
break;
case "next":
PidoraCTL("n");
break;
default:
break;
}
});
});

player.canSeek = false;
player.canGoPrevious = false;
player.playbackStatus = "Stopped";
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "A web frontend for pianobar, which is a CLI frontend for Pandora.",
"dependencies": {
"express": "^4.17.1",
"mpris-service": "^2.1.2",
"socket.io": "2.4.0"
}
}