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

Synchronise stream volume with app volume #3

Merged
merged 2 commits into from
Sep 27, 2015
Merged
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Rdio for Nuvola Player 3

Integration of Rdio into your linux desktop via
[Nuvola Player](https://github.com/tiliado/nuvolaplayer).

Support
-------

Expand All @@ -19,6 +19,7 @@ Installation

Copyright
---------
- Copyright 2015 Jordan Klassen <[email protected]>
- Copyright 2015 Aaron Cripps <[email protected]>
- Copyright 2014 Jiří Janoušek <[email protected]>
- Copyright 2014 Martin Pöhlmann <[email protected]>
Expand Down
20 changes: 19 additions & 1 deletion integrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright 2014 Martin Pöhlmann <[email protected]>
* Copyright 2014 Jiří Janoušek <[email protected]>
* Copyright 2015 Aaron Cripps <[email protected]>
* Copyright 2015 Jordan Klassen <[email protected]>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -75,7 +76,7 @@
}

var state = PlaybackState.UNKNOWN;

try
{
var playingTrack = R.Services.Player.model.get("playingTrack").attributes;
Expand Down Expand Up @@ -116,6 +117,23 @@
player.setCanPlay(canPlay);
player.setCanPause(canPause);

// synchronise stream volume with app volume
if (state == PlaybackState.PLAYING) {
try {
var playerVolume = R.Services.Player.volume();
var streamVolume = R.Services.Player._audio._element.volume;
if (streamVolume != null) {
streamVolume = Math.sqrt(streamVolume);
if (Math.abs(streamVolume - playerVolume) >= 0.01) {
R.Services.Player.volume(streamVolume);
}
}
}
catch (e) {
// do nothing
}
}

// Schedule the next update
setTimeout(this.update.bind(this), 500);
}
Expand Down