/// <summary> /// не работает /// </summary> /// <param name="delay"></param> /// <param name="_basicplayer"></param> /// <returns></returns> public async Task FadeOut2(float delay, BasicPlayerFunction _basicplayer) { try { TimeSpan time = TimeSpan.FromMilliseconds(delay); int iVolume = (int)_basicplayer.Volume;//*100; while (_basicplayer.Volume > VOLUME_MIN) { iVolume = iVolume - 2; double fVolume = 1 - ((float)Math.Log(INT_VOLUME_MAX - iVolume) / (float)Math.Log(INT_VOLUME_MAX)); if (fVolume < FLOAT_VOLUME_MIN) { fVolume = FLOAT_VOLUME_MIN; break; } await Task.Delay(time); await Task.Run(() => { _basicplayer.Volume = fVolume; }); } _basicplayer.Stop(); } catch (OperationCanceledException ex) { //Do stuff to handle cancellation MessageBox.Show("OperationCanceledException " + ex); } }
public async Task FadeOut(float duration, BasicPlayerFunction _basicplayer) { try { float time = duration; while (_basicplayer.Volume > VOLUME_MIN) { time -= 20; float volume = ((float)_basicplayer.Volume * time) / duration; await Task.Delay(100); await Task.Run(() => { _basicplayer.Volume = volume; }); } _basicplayer.Stop(); } catch (OperationCanceledException ex) { //Do stuff to handle cancellation MessageBox.Show("OperationCanceledException " + ex); } }