@@ -26,7 +26,6 @@ struct Controls {
26
26
volume : Mutex < f32 > ,
27
27
stopped : AtomicBool ,
28
28
speed : Mutex < f32 > ,
29
- do_skip : AtomicBool ,
30
29
to_clear : Mutex < u32 > ,
31
30
}
32
31
@@ -52,7 +51,6 @@ impl Sink {
52
51
volume : Mutex :: new ( 1.0 ) ,
53
52
stopped : AtomicBool :: new ( false ) ,
54
53
speed : Mutex :: new ( 1.0 ) ,
55
- do_skip : AtomicBool :: new ( false ) ,
56
54
to_clear : Mutex :: new ( 0 ) ,
57
55
} ) ,
58
56
sound_count : Arc :: new ( AtomicUsize :: new ( 0 ) ) ,
@@ -79,6 +77,8 @@ impl Sink {
79
77
80
78
let controls = self . controls . clone ( ) ;
81
79
80
+ let start_played = AtomicBool :: new ( false ) ;
81
+
82
82
let source = source
83
83
. speed ( 1.0 )
84
84
. pausable ( false )
@@ -89,13 +89,10 @@ impl Sink {
89
89
if controls. stopped . load ( Ordering :: SeqCst ) {
90
90
src. stop ( ) ;
91
91
}
92
- if controls. do_skip . load ( Ordering :: SeqCst ) {
93
- let _ = src. inner_mut ( ) . skip ( ) ;
92
+ {
94
93
let mut to_clear = controls. to_clear . lock ( ) . unwrap ( ) ;
95
- if * to_clear == 1 {
96
- controls. do_skip . store ( false , Ordering :: SeqCst ) ;
97
- * to_clear = 0 ;
98
- } else if * to_clear > 0 {
94
+ if * to_clear > 0 {
95
+ let _ = src. inner_mut ( ) . skip ( ) ;
99
96
* to_clear -= 1 ;
100
97
}
101
98
}
@@ -106,6 +103,7 @@ impl Sink {
106
103
amp. inner_mut ( )
107
104
. inner_mut ( )
108
105
. set_factor ( * controls. speed . lock ( ) . unwrap ( ) ) ;
106
+ start_played. store ( true , Ordering :: SeqCst ) ;
109
107
} )
110
108
. convert_samples ( ) ;
111
109
self . sound_count . fetch_add ( 1 , Ordering :: Relaxed ) ;
@@ -180,7 +178,7 @@ impl Sink {
180
178
pub fn clear ( & self ) {
181
179
let len = self . sound_count . load ( Ordering :: SeqCst ) as u32 ;
182
180
* self . controls . to_clear . lock ( ) . unwrap ( ) = len;
183
- self . skip_one ( ) ;
181
+ self . sleep_until_end ( ) ;
184
182
self . pause ( ) ;
185
183
}
186
184
@@ -190,7 +188,11 @@ impl Sink {
190
188
/// it will play the next one. Otherwise, the `Sink` will finish as if
191
189
/// it had finished playing a `Source` all the way through.
192
190
pub fn skip_one ( & self ) {
193
- self . controls . do_skip . store ( true , Ordering :: SeqCst ) ;
191
+ let len = self . sound_count . load ( Ordering :: SeqCst ) as u32 ;
192
+ let mut to_clear = self . controls . to_clear . lock ( ) . unwrap ( ) ;
193
+ if len > * to_clear {
194
+ * to_clear += 1 ;
195
+ }
194
196
}
195
197
196
198
/// Stops the sink by emptying the queue.
0 commit comments