SoundEffectInstance alarmSound = PlaySound(@"Alarms/"+alarmSoundString);
VibrateController vibrate = VibrateController.Default;
var vibrationLength = 1000;
var startTime = DateTime.Now;
vibrate.Start(new TimeSpan(0,0,0,0,vibrationLength));
MessageBoxResult alarmBox = MessageBox.Show("Press OK to stop alarm", "Timer Finished", MessageBoxButton.OK);
var ok = false;
While (!ok){
if (alarmBox == MessageBoxResult.OK)
{
ok = true;
}
else{
if(startTime.AddMilliseconds(vibrationLength * 1.2) < DateTime.Now)
{
startTime = DateTimne.Now;
vibrate.Start(new TimeSpan(0,0,0,0,vibrationLength));
}
}
}
alarmSound.Stop();
vibrate.Stop();
grubsza
Nie piszę kod dla Windows Phone, więc to może spowodować, że telefon przestanie odpowiadać. Ale ogólną ideą jest sprawdzanie, czy użytkownik trafił w porządku, a jeśli nie, to wystarczy czasu, zanim zaczęły się nowe wibracje.
Jeśli chcesz impulsować, sugerowałbym użycie AddMilliseconds i dodanie długości większej niż długość impulsu.
Korzystanie czasomierza zamiast
udaje ci klasy wygląda następująco
public class buzzz
{
MessageBoxResult alarmBox;
DispatchTimer alarmTimer = new DispatchTimer();
var vibrationLength = 1000.0;
var timerIncrease = 1.2;
VibrateController vibrate = VibrateController.Default;
public buzz()
{
alarmTimer.Interval = TimeSpan.FromMillseconds(vibrationLegnth * timerIncrease);
alarmTimer.Tick += alarmTimer_Tick
}
public void startBuzz()
{
SoundEffectInstance alarmSound = PlaySound(@"Alarms/"+alarmSoundString);
vibrate.Start(new TimeSpan(0,0,0,0,vibrationLength));
alarmTimer.Start();
alarmBox = MessageBox.Show("Press OK to stop alarm", "Timer Finished", MessageBoxButton.OK);
}
void alarmTimer_Tick(object sender, EventArgs e)
{
if(alarmBox == MessageBoxResult.OK)
{
alarmTimer.Stop();
vibrate.Stop();
}
else
{
vibrate.Start(new TimeSpan(0,0,0,0,vibrationLength));
}
}
}
chcesz go wibrować ciągły lub impulsowy? – Joe
@Joe Chcę, żeby zadzwonił – Chris
Powinieneś się upewnić, że upłynął czas po jakimś czasie, w przeciwnym razie możesz ryzykować wyczerpanie baterii dla kogoś, kto zostawił swój telefon w innym pokoju. –