File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,11 @@ impl LMS {
44
44
self . request ( r#"["spottyconnect","change"]"# . to_string ( ) )
45
45
}
46
46
47
+ pub fn volume ( & self , volume : u16 ) {
48
+ // we're not using the volume here, as LMS will read player state anyway
49
+ self . request ( format ! ( r#"["spottyconnect","volume",{}]"# , volume. to_string( ) ) )
50
+ }
51
+
47
52
pub fn request ( & self , command : String ) {
48
53
debug ! ( "Base URL to talk to LMS: {}" , self . base_url. clone( ) . unwrap( ) ) ;
49
54
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ enum PlayerCommand {
40
40
Pause ,
41
41
Stop ,
42
42
Seek ( u32 ) ,
43
+ Volume ( u32 ) ,
43
44
}
44
45
45
46
impl Player {
@@ -96,6 +97,10 @@ impl Player {
96
97
pub fn seek ( & self , position_ms : u32 ) {
97
98
self . command ( PlayerCommand :: Seek ( position_ms) ) ;
98
99
}
100
+
101
+ pub fn set_volume ( & self , volume : u32 ) {
102
+ self . command ( PlayerCommand :: Volume ( volume) ) ;
103
+ }
99
104
}
100
105
101
106
type Decoder = vorbis:: Decoder < Subfile < AudioDecrypt < AudioFile > > > ;
@@ -286,6 +291,25 @@ impl PlayerInternal {
286
291
self . run_onchange ( ) ;
287
292
}
288
293
294
+ PlayerCommand :: Volume ( mut volume) => {
295
+ if self . lms . is_configured ( ) {
296
+ if volume > 0 {
297
+ volume = volume * 100 / std:: u16:: MAX as u32 ;
298
+ } else {
299
+ volume = 0 ;
300
+ }
301
+
302
+ // LMS volume is 0-100. We need to convert
303
+ let v2 = if volume > 100 {
304
+ Some ( 100 as u16 )
305
+ } else {
306
+ Some ( volume as u16 )
307
+ } ;
308
+
309
+ self . lms . volume ( v2. unwrap ( ) ) ;
310
+ }
311
+ }
312
+
289
313
PlayerCommand :: Play => {
290
314
if let PlayerState :: Paused { .. } = self . state {
291
315
self . state . paused_to_playing ( ) ;
@@ -453,6 +477,11 @@ impl ::std::fmt::Debug for PlayerCommand {
453
477
. field ( & position)
454
478
. finish ( )
455
479
}
480
+ PlayerCommand :: Volume ( volume) => {
481
+ f. debug_tuple ( "Volume" )
482
+ . field ( & volume)
483
+ . finish ( )
484
+ }
456
485
}
457
486
}
458
487
}
Original file line number Diff line number Diff line change @@ -410,6 +410,7 @@ impl SpircTask {
410
410
411
411
MessageType :: kMessageTypeVolume => {
412
412
let volume = frame. get_volume ( ) ;
413
+ self . player . set_volume ( volume) ;
413
414
self . device . set_volume ( volume) ;
414
415
self . mixer . set_volume ( frame. get_volume ( ) as u16 ) ;
415
416
self . notify ( None ) ;
You can’t perform that action at this time.
0 commit comments