protected override void OnDisappearing() { base.OnDisappearing(); if (_performer != null) _performer.Dispose(); if (_textToSpeech != null) _textToSpeech.Dispose(); //_soundService.Dispose(); _performer = null; _textToSpeech = null; //_soundService = null; }
public TimeSetRunPage(TimeSet timeSet) { this.TimeSet = timeSet; _isEnglish = timeSet.IsEnglish; Title = "执行倒计时"; BackgroundColor = Color.FromHex("#eee"); _textToSpeech = DependencyService.Get<ITextToSpeech>().New(); _textToSpeech.Inited += _textToSpeech_Init; _textToSpeech.InitedError += _textToSpeech_InitedError; _textToSpeech.Init(TimeSet.VoiceEngine); _soundService = DependencyService.Get<ISoundService>(); // _performer = new Performer(this.TimeSet); _performer.Speak += performer_Speak; _performer.PrepareTick += performer_PrepareTick; _performer.Tick += performer_HeartBeat; _performer.CurrentSecondChanged += performer_CurrentSecondChanged; _performer.StageChanged += performer_StageChanged; InitView(); //_textToSpeech.Speak(timeSet.Name); }
void performer_StageChanged(object sender, Performer.StageChangedEventArgs e) { try { Device.BeginInvokeOnMainThread(() => { _stageListView.SelectedItem = e.CurrentStage; }); } catch (Exception) { } }
void performer_Speak(object sender, Performer.SpeakEventArgs e) { try { //if (e.VoiceInterval > 2) //{ // var ts = TimeSpan.FromSeconds(e.Seconds); // var text = ""; // var hours = ts.Hours; // var minutes = ts.Minutes; // var seconds = ts.Seconds; // if (_isEnglish) // { // if (hours > 0) // { // text += string.Format("{0} hour{1}", hours, hours > 1 ? "s" : ""); // } // if (minutes > 0) // { // text += string.Format(" {0} minute{1}", minutes, minutes > 1 ? "s" : ""); // } // if (seconds > 0) // { // text += string.Format(" and {0} second{1}", seconds, seconds > 1 ? "s" : ""); // } // } // else // { // if (hours > 0) // { // text += string.Format("{0}小时", hours); // } // if (minutes > 0) // { // text += string.Format("{0}分", minutes); // } // if (seconds > 0) // { // text += string.Format("{0}秒", seconds); // } // } // _textToSpeech.Speak(text); //} //else //{ // _textToSpeech.Speak(e.Seconds.ToString()); //} _textToSpeech.Speak(e.Text); } catch (Exception) { } }
void performer_PrepareTick(object sender, Performer.PrepareTickEventArgs e) { try { if (e.IsAtStartPoint) { Device.BeginInvokeOnMainThread(() => { _circle.Text = "准备"; }); //var timeSet = sender as TimeSet; //if (_textToSpeech.CurrentEngine != timeSet.VoiceEngine) //{ // _textToSpeech.SetEngine(timeSet.VoiceEngine); //} //var text = string.Format("{0}秒准备", e.TotalSeconds); string text = ""; if (_isEnglish) { text = string.Format("{0} second{1} for ready ", e.TotalSeconds, e.TotalSeconds > 1 ? "s" : ""); } else { text = string.Format("{0}秒准备", e.TotalSeconds); } _textToSpeech.Speak(text); } _soundService.PlayDi(); } catch (Exception) { } }
void performer_CurrentSecondChanged(object sender, Performer.SecondChangedEvenArgs e) { Device.BeginInvokeOnMainThread(() => { try { _circle.Text = e.Current.ToString(); if (e.Current == 0) { Device.BeginInvokeOnMainThread(() => { _startBtn.IsEnabled = true; _stopBtn.IsEnabled = false; _pauseBtn.IsEnabled = false; }); _circle.RotateTo(360, length: 500).ContinueWith(r => { Device.BeginInvokeOnMainThread(() => { _circle.Text = "结束"; }); }); } } catch (Exception) { } }); }