private void ThreadHandler() { float last = 0; _tickCount = 0; _playback.Load(_sequence); _stopWatch = new Stopwatch(); _stopWatch.Start(); _playback.Start(); _playing = true; while (_playing) { // if we hit our interval if ((_stopWatch.ElapsedMilliseconds - last) >= _sequence.Interval) { // make sure we're still inside the bounds of the song if (_tickCount >= _sequence.Channels[0].Data.Length) { // dump out and let anyone listening know it's all over Thread.Sleep(100); _stopWatch.Stop(); _playback.Stop(); OnSequenceStopped(new EventArgs()); return; } // every time we tick, set the output port for the current channel on or off foreach (Channel c in _sequence.Channels) { if (PhidgetHandler.IFKits[c.SerialNumber].outputs[c.OutputIndex] != c.Data[_tickCount]) { PhidgetHandler.IFKits[c.SerialNumber].outputs[c.OutputIndex] = c.Data[_tickCount]; } } _tickCount++; last = (_stopWatch.ElapsedMilliseconds - ((_stopWatch.ElapsedMilliseconds - last) - _sequence.Interval)); } else { Thread.Sleep((int)(_stopWatch.ElapsedMilliseconds - last)); // give the CPU a break until it's time to act again } } Thread.Sleep(100); _stopWatch.Stop(); _playback.Stop(); }
void tmrTimer_Tick(object sender, EventArgs e) { if (_tickCount >= _sequence.Channels[0].Data.Length) { _playback.Stop(); tmrTimer.Enabled = false; OnSequenceStopped(new EventArgs()); return; } // every time we tick, set the output port for the current channel on or off foreach (Channel c in _sequence.Channels) { PhidgetHandler.IFKits[c.SerialNumber].outputs[c.OutputIndex] = c.Data[_tickCount]; } _tickCount++; }
public void StopSound() { lock (lockObjectForSound) { if (playback != null) { Logger.Info("Stop all sounds"); playback.Stop(); playback = null; } } }
private DialogResult StopRecording() { tmrCountdown.Enabled = false; _playing = false; btnStart.Text = "&Start"; _playback.Stop(); lblCountdown.Text = "3"; DialogResult dr = MessageBox.Show("Do you want to save the recorded data to the main grid?", "Save Recording", MessageBoxButtons.YesNo, MessageBoxIcon.Question); switch (dr) { case DialogResult.Yes: // save off the channel data to the main grid for (int i = 0; i < _tempData.Count; i++) { for (int j = 0; j < _tempData[i].Length; j++) { if (_tempData[i][j] || radOverwrite.Checked) { _channels[i].Data[j] = _tempData[i][j]; } } } this.Close(); break; case DialogResult.No: for (int i = 0; i < _tempData.Count; i++) { Array.Clear(_tempData[i], 0, _tempData[i].Length); } break; } return(dr); }
public static void Dispose(this IPlayback playback) { var disposable = playback as IDisposable; if (disposable != null) { disposable.Dispose(); return; } playback.Stop(); playback.ClearOutgoingConnections(); }
public void StopDoorBell() { if (stream != null) { lock (lockObjectForSound) { if (stream != null) { stream.Stop(); stream = null; } } } }
public void SwitchToPlayback(IPlayback playback, bool resumePlaying) { if (playback == null) { throw new ArgumentException("Playback cannot be null"); } // suspend the current one. int oldState = Playback.State; int pos = Playback.CurrentStreamPosition; var currentMediaId = Playback.CurrentMediaId; Playback.Stop(false); Playback.Callback = this; Playback.CurrentStreamPosition = pos < 0 ? 0 : pos; Playback.CurrentMediaId = currentMediaId; Playback.Start(); // finally swap the instance Playback = playback; switch (oldState) { case PlaybackStateCompat.StateBuffering: case PlaybackStateCompat.StateConnecting: case PlaybackStateCompat.StatePaused: Playback.Pause(); break; case PlaybackStateCompat.StatePlaying: MediaSessionCompat.QueueItem currentMusic = queueManager.CurrentMusic; if (resumePlaying && currentMusic != null) { Playback.Play(currentMusic); } else if (!resumePlaying) { Playback.Pause(); } else { Playback.Stop(true); } break; case PlaybackStateCompat.StateNone: break; default: LogHelper.Debug(Tag, "Default called. Old state is ", oldState); break; } }
public static void Stop(int stream) { _Playback.Stop(stream); }
public void Stop() { _playback?.Stop(); CurrentTrack = Tracks.First(); }