@@ -8,7 +8,7 @@ use std::{
88 time:: Duration ,
99} ;
1010
11- use rodio:: { buffer:: SamplesBuffer , Decoder , OutputStream , Source } ;
11+ use rodio:: { buffer:: SamplesBuffer , Decoder , OutputStreamBuilder , Sink , Source } ;
1212
1313use crate :: core:: { base:: Res , note:: Note } ;
1414
@@ -26,7 +26,7 @@ pub fn get_audio_data_from_file(file: impl AsRef<Path>, start: Option<Duration>,
2626 let path = file. as_ref ( ) ;
2727 let start = start. unwrap_or_default ( ) ;
2828
29- let decoder = Decoder :: new ( File :: open ( path) ?) ?. skip_duration ( start) . convert_samples ( ) ;
29+ let decoder = Decoder :: new ( File :: open ( path) ?) ?. skip_duration ( start) ;
3030
3131 let num_channels = decoder. channels ( ) ;
3232 let sample_rate = decoder. sample_rate ( ) ;
@@ -53,15 +53,18 @@ pub fn preview_audio_file_clip(file: impl AsRef<Path>, start: Option<Duration>,
5353#[ coverage( off) ]
5454pub fn preview_audio_clip ( stream : impl Read + Seek + Send + Sync + ' static , start : Option < Duration > , end : Option < Duration > ) -> Res < ( ) > {
5555 let start = start. unwrap_or_default ( ) ;
56- let decoder = Decoder :: new ( stream) ?. skip_duration ( start) . convert_samples ( ) ;
56+ let decoder = Decoder :: new ( stream) ?. skip_duration ( start) ;
5757
58- let ( _stream, stream_handle) = OutputStream :: try_default ( ) ?;
58+ let stream = OutputStreamBuilder :: open_default_stream ( ) ?;
59+ let sink = Sink :: connect_new ( stream. mixer ( ) ) ;
5960
6061 if let Some ( end) = end {
61- stream_handle. play_raw ( decoder. take_duration ( end - start) ) ?;
62+ stream. mixer ( ) . add ( decoder. take_duration ( end - start) ) ;
63+ sink. play ( ) ;
6264 sleep ( end - start) ;
6365 } else if let Some ( duration) = decoder. total_duration ( ) {
64- stream_handle. play_raw ( decoder) ?;
66+ stream. mixer ( ) . add ( decoder) ;
67+ sink. play ( ) ;
6568 sleep ( duration) ;
6669 } else {
6770 let channels = decoder. channels ( ) ;
@@ -70,7 +73,8 @@ pub fn preview_audio_clip(stream: impl Read + Seek + Send + Sync + 'static, star
7073
7174 let time = Duration :: from_secs ( ( samples. len ( ) as f32 / sample_rate) . ceil ( ) as u64 ) ;
7275
73- stream_handle. play_raw ( SamplesBuffer :: new ( channels, sample_rate as u32 , samples) ) ?;
76+ stream. mixer ( ) . add ( SamplesBuffer :: new ( channels, sample_rate as u32 , samples) ) ;
77+ sink. play ( ) ;
7478
7579 sleep ( time) ;
7680 }
0 commit comments