Skip to content

Commit

Permalink
mpris integration / media key support on linux
Browse files Browse the repository at this point in the history
Grabs patched dbus & then rebuilds it for NW 0.12.3.
Currently doesn't support all of the mpris features registered due to a bug in the player
Should support all features once the bug is fixed :)
  • Loading branch information
jakejarrett committed Feb 13, 2016
1 parent 03315c2 commit 64335f4
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ <h4 id="playerUser" class="player_user" ng-click="goToUser($event)"></h4>
<script src="public/js/common/SCapiService.js"></script>
<script src="public/js/common/SC2apiService.js"></script>
<script src="public/js/common/playerService.js"></script>
<script src="public/js/common/mprisService.js"></script>
<script src="public/js/common/notificationFactory.js"></script>
<script src="public/js/common/modalFactory.js"></script>

Expand Down
47 changes: 47 additions & 0 deletions app/public/js/common/mprisService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use strict";

var gui = require("nw.gui");

app.factory("mprisService", function($rootScope, $log, $timeout, $window, $state) {
if("linux" !== process.platform) {
return false;
}

var Player = require("mpris-service");

var mprisPlayer = Player({
name: "soundnode",
identity: "Soundnode Player",
supportedUriSchemes: ["http", "file"],
supportedMimeTypes: ["audio/mpeg", "application/ogg"],
supportedInterfaces: ["player"]
});

mprisPlayer.on("raise", function() {
gui.Window.get().show();
});

mprisPlayer.canControl = true;

mprisPlayer.canSeek = false;

// Export Functions
mprisPlayer.play = function(length, artwork, title, artist) {
mprisPlayer.metadata = {
"mpris:trackid": mprisPlayer.objectPath("track/0"),
"mpris:length": length,
"mpris:artUrl": artwork,
"xesam:title": title,
"xesam:album": "",
"xesam:artist": artist
};

mprisPlayer.playbackStatus = "Playing";
};

mprisPlayer.pause = function() {
mprisPlayer.playbackStatus = "Paused";
};

return mprisPlayer;
});
26 changes: 26 additions & 0 deletions app/public/js/common/playerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ app.factory('playerService', function(
$timeout,
$window,
$state,
mprisService,
notificationFactory,
queueService,
utilsService
Expand Down Expand Up @@ -309,6 +310,31 @@ app.factory('playerService', function(

});

/**
* Handle mpris Calls
*/
if(process.platform === "linux") {
mprisService.on('playpause', function() {
if($rootScope.isSongPlaying) {
player.pauseSong();
} else {
player.playSong();
}
});

mprisService.on("next", function() {
player.playNextSong();
});

mprisService.on("previous", function() {
player.playPrevSong();
});

mprisService.on("shuffle", function() {
player.shuffle();
});
}

/**
* Responsible to add scrubbing
* drag or click scrub on track progress bar
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"webpack": "^1.12.2"
},
"dependencies": {
"mpris-service": "^1.1.0",
"react": "^0.14.2",
"react-dom": "^0.14.2",
"universal-analytics": "^0.3.9"
Expand Down
3 changes: 2 additions & 1 deletion tasks/nwjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ var config = {
'<%= settings.app %>/public/img/**/*',
'<%= settings.app %>/public/stylesheets/css/**/*',
'<%= settings.app %>/dist/**/*',
'./node_modules/universal-analytics/**/*'
'./node_modules/universal-analytics/**/*',
'./node_modules/mpris-service/**/*'
]
};

Expand Down
9 changes: 8 additions & 1 deletion tasks/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ module.exports = {
stdout: true
},
target: {
command: 'webpack -p'
command: 'webpack -p',
command: function() {
if("linux" === process.platform) {
return 'rm -r ./node_modules/mpris-service/node_modules/dbus && git clone https://github.com/daloe/node-dbus.git ./node_modules/mpris-service/node_modules/dbus && cd ./node_modules/mpris-service/node_modules/dbus && git checkout fix_fail_to_load && npm install && nw-gyp rebuild --target=0.12.3';
} else {
return '';
}
}
}
};

0 comments on commit 64335f4

Please sign in to comment.