@@ -4,7 +4,7 @@ use std::thread::sleep;
4
4
use std:: time:: Duration ;
5
5
6
6
use crate :: subsystems:: config_manager:: ConfigCommand ;
7
- use anyhow:: { anyhow, Error , Result } ;
7
+ use anyhow:: { anyhow, Context , Error , Result } ;
8
8
use glob:: glob;
9
9
use log:: info;
10
10
use rand:: seq:: SliceRandom ;
@@ -63,7 +63,7 @@ impl AudioPlayer {
63
63
64
64
async fn process ( & mut self ) -> Result < ( ) > {
65
65
let ( soloud_tx, mut soloud_rx) = mpsc:: channel ( 8 ) ;
66
- let share_path = self . share_path . to_str ( ) . unwrap ( ) . to_owned ( ) ;
66
+ let share_path = self . share_path . to_owned ( ) ;
67
67
68
68
thread:: spawn ( move || {
69
69
struct PlayState {
@@ -73,26 +73,30 @@ impl AudioPlayer {
73
73
74
74
let mut soloud = Soloud :: default ( ) . unwrap ( ) ;
75
75
let mut play_wav = audio:: Wav :: default ( ) ;
76
+ let volume_change_path = share_path. join ( Path :: new ( "volume-change.mp3" ) ) ;
76
77
let mut volume_change_wav = audio:: Wav :: default ( ) ;
77
- volume_change_wav
78
- . load ( format ! ( "{}/volume-change.mp3" , share_path) )
79
- . unwrap ( ) ;
78
+ volume_change_wav. load ( volume_change_path) . unwrap ( ) ;
80
79
81
80
let mut handle_command = |soloud : & mut Soloud , command| {
82
81
use SoloudCommand :: * ;
83
82
84
83
match command {
85
84
PlayAsset { path, done } => {
85
+ let path = share_path. join ( path) ;
86
86
play_wav
87
- . load ( format ! ( "{}/{}" , share_path, path. to_str( ) . unwrap( ) ) )
87
+ . load ( & path)
88
+ . with_context ( || format ! ( "Failed to play {}" , path. display( ) ) )
88
89
. unwrap ( ) ;
89
90
return Some ( PlayState {
90
91
handle : soloud. play ( & play_wav) ,
91
92
done,
92
93
} ) ;
93
94
}
94
95
PlayFile { path, done } => {
95
- play_wav. load ( path) . unwrap ( ) ;
96
+ play_wav
97
+ . load ( & path)
98
+ . with_context ( || format ! ( "Failed to play {}" , path. display( ) ) )
99
+ . unwrap ( ) ;
96
100
return Some ( PlayState {
97
101
handle : soloud. play ( & play_wav) ,
98
102
done,
0 commit comments