Skip to content
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
2 changes: 1 addition & 1 deletion connect/src/spirc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ impl SpircTask {
}

fn set_volume(&mut self, volume: u16) {
self.device.set_volume(volume as u32);
self.player.set_volume(volume as u32);
self.mixer
.set_volume(volume_to_mixer(volume, &self.config.volume_ctrl));
if let Some(cache) = self.session.cache() {
Expand Down
2 changes: 2 additions & 0 deletions playback/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub struct PlayerConfig {
pub normalisation_knee: f32,
pub gapless: bool,
pub passthrough: bool,
pub lms_connect_mode: bool,
}

impl Default for PlayerConfig {
Expand All @@ -144,6 +145,7 @@ impl Default for PlayerConfig {
normalisation_knee: 1.0,
gapless: true,
passthrough: false,
lms_connect_mode: false,
}
}
}
30 changes: 30 additions & 0 deletions playback/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ enum PlayerCommand {
Pause,
Stop,
Seek(u32),
Volume(u32),
AddEventSender(mpsc::UnboundedSender<PlayerEvent>),
SetSinkEventCallback(Option<SinkEventCallback>),
EmitVolumeSetEvent(u16),
Expand All @@ -94,6 +95,12 @@ pub enum PlayerEvent {
play_request_id: u64,
track_id: SpotifyId,
},
Volume {
volume: u32
},
Seek {
position: u32
},
// The player started working on playback of a track while it was in a stopped state.
// This is always immediately followed up by a "Loading" or "Playing" event.
Started {
Expand Down Expand Up @@ -189,6 +196,8 @@ impl PlayerEvent {
| Stopped {
play_request_id, ..
} => Some(*play_request_id),
//I'm not sure of that...
Volume { .. } | Seek { .. } => None,
Changed { .. } | Preloading { .. } | VolumeSet { .. } => None,
}
}
Expand Down Expand Up @@ -365,6 +374,10 @@ impl Player {
pub fn seek(&self, position_ms: u32) {
self.command(PlayerCommand::Seek(position_ms));
}

pub fn set_volume(&self, volume: u32) {
self.command(PlayerCommand::Volume(volume));
}

pub fn get_player_event_channel(&self) -> PlayerEventChannel {
let (event_sender, event_receiver) = mpsc::unbounded_channel();
Expand Down Expand Up @@ -1706,6 +1719,20 @@ impl PlayerInternal {
});
}
}

fn handle_command_volume(&mut self, mut volume: u32) {
if volume > 0 {
volume = volume * 100 / std::u16::MAX as u32;
} else {
volume = 0;
}

if volume > 100 {
volume = 100;
};

self.send_event(PlayerEvent::Volume { volume });
}

fn handle_command(&mut self, cmd: PlayerCommand) {
debug!("command={:?}", cmd);
Expand All @@ -1720,6 +1747,8 @@ impl PlayerInternal {
PlayerCommand::Preload { track_id } => self.handle_command_preload(track_id),

PlayerCommand::Seek(position_ms) => self.handle_command_seek(position_ms),

PlayerCommand::Volume(volume) => self.handle_command_volume(volume),

PlayerCommand::Play => self.handle_play(),

Expand Down Expand Up @@ -1832,6 +1861,7 @@ impl ::std::fmt::Debug for PlayerCommand {
PlayerCommand::Pause => f.debug_tuple("Pause").finish(),
PlayerCommand::Stop => f.debug_tuple("Stop").finish(),
PlayerCommand::Seek(position) => f.debug_tuple("Seek").field(&position).finish(),
PlayerCommand::Volume(volume) => f.debug_tuple("Volume").field(&volume).finish(),
PlayerCommand::AddEventSender(_) => f.debug_tuple("AddEventSender").finish(),
PlayerCommand::SetSinkEventCallback(_) => {
f.debug_tuple("SetSinkEventCallback").finish()
Expand Down