@@ -17,6 +17,8 @@ public partial class MainWindow : Window
1717 double volume ;
1818 double prevVolume ;
1919 string path ;
20+ bool FirstRun = true ;
21+ Thread LoopingThread ;
2022
2123
2224 WMPLib . WindowsMediaPlayer player ;
@@ -33,8 +35,10 @@ public MainWindow()
3335 player . uiMode = "full" ;
3436 VolumeUpdate ( ) ;
3537 SongSelect ( ) ;
38+ LoopingThread = new Thread ( Looper ) ;
39+ LoopingThread . Start ( ) ;
40+
3641
37- player . PositionChange += UpdateSongPosition ;
3842 //DelayAction(3000, TimerLoop);
3943
4044
@@ -55,45 +59,41 @@ private void SongSelect()
5559 {
5660 path = file . FileName ;
5761 }
58- else
59- {
60- SongSelect ( ) ;
61- }
6262 Console . WriteLine ( path ) ;
6363 player . URL = path ;
6464 Current_Playing . Text = player . currentMedia . name ;
65- Progress_Slider . Maximum = Convert . ToInt32 ( player . currentMedia . duration ) ;
66- Console . WriteLine ( player . currentMedia . durationString ) ;
67- Max_Time . Text = player . currentMedia . durationString ;
68-
69-
70-
7165
7266
7367 }
7468
75- private void TimerLoop ( )
69+
70+ private void Looper ( )
7671 {
77- try
72+ if ( FirstRun )
7873 {
79- while ( Progress_Slider . Value != player . controls . currentPosition * 100 / player . currentMedia . duration )
80- {
81-
82- Progress_Slider . Value = player . controls . currentPosition * 100 / player . currentMedia . duration ;
83-
84-
85- }
74+ Thread . Sleep ( 50 ) ;
75+ FirstRun = false ;
8676 }
87- catch
77+ while ( true )
8878 {
89-
79+ System . Threading . Thread . Sleep ( 100 ) ;
80+
81+
82+ if ( player . currentMedia . duration > 1 && player . controls . currentPosition > 1 )
83+ {
84+ this . Dispatcher . Invoke ( ( ) =>
85+ {
86+ UpdateSongPosition ( ) ;
87+ } ) ;
88+ }
89+
90+
9091 }
9192 }
92-
93- private void UpdateSongPosition ( double a , double b )
94- {
9593
96- Progress_Slider . Value = player . controls . currentPosition * 100 / player . currentMedia . duration ;
94+ private void UpdateSongPosition ( )
95+ {
96+ Progress_Slider . Value = player . controls . currentPosition ;
9797 Current_Time . Text = player . controls . currentPositionString ;
9898 Progress_Slider . Maximum = player . currentMedia . duration ;
9999 Max_Time . Text = player . currentMedia . durationString ;
@@ -165,7 +165,12 @@ public static void DelayAction(int millisecond, Action action)
165165
166166 private void temp ( object sender , RoutedEventArgs e )
167167 {
168- UpdateSongPosition ( 0 , 0 ) ;
168+ UpdateSongPosition ( ) ;
169+ }
170+
171+ private void Close ( object sender , System . ComponentModel . CancelEventArgs e )
172+ {
173+ LoopingThread . Abort ( ) ;
169174 }
170175 }
171176}
0 commit comments