private void PlayClip(string filePath, bool startpaused) { using (KStudioClient client = KStudio.CreateClient()) { client.ConnectToService(); KStudioPlaybackFlags flags = KStudioPlaybackFlags.IgnoreOptionalStreams; try { playback = client.CreatePlayback(filePath, flags); } catch (Exception ex) { FLogger.Log(LogType.Debug, ex.ToString()); } using (playback) { playback.PropertyChanged += Playback_PropertyChanged; playback.StateChanged += Playback_StateChanged; playback.LoopCount = 0; playback.InPointByRelativeTime = TimeSpan.FromSeconds(FInputInPoint[0]); playback.OutPointByRelativeTime = TimeSpan.FromSeconds(Math.Min(FInputOutPoint[0], playback.Duration.TotalSeconds)); var kStudioMetadata = playback.GetMetadata(KStudioMetadataType.Public); if (startpaused) { playback.StartPaused(); } else { playback.Start(); }; FRecordTotalDuration[0] = playback.Duration.TotalSeconds; while ((playback.State == KStudioPlaybackState.Playing) || (playback.State == KStudioPlaybackState.Paused) && (doPlay)) { if (doStep) { if ((playback.State == KStudioPlaybackState.Playing)) { playback.Pause(); } if (playback.State == KStudioPlaybackState.Paused) { playback.StepOnce(); Thread.Sleep(20); } doStep = false; } Thread.Sleep(20); } playback.Stop(); } playback = null; client.DisconnectFromService(); } }
public void Pause() { if (Playback != null) { if (_playback.State == KStudioPlaybackState.Playing) { _playback.Pause(); } return; } if (_kinect != null) { stopKinect(); return; } }
/// <summary> /// Run /// </summary> private void Run() { client.ConnectToService(); using (KStudioPlayback play = client.CreatePlayback(path)) { play.EndBehavior = KStudioPlaybackEndBehavior.Stop; play.Mode = KStudioPlaybackMode.TimingEnabled; play.LoopCount = loop; play.Start(); while (play.State.Equals(KStudioPlaybackState.Playing) || play.State.Equals(KStudioPlaybackState.Paused)) { Thread.Sleep(33); if (isPause && !play.State.Equals(KStudioPlaybackState.Paused)) { play.Pause(); } if (!isPause && play.State.Equals(KStudioPlaybackState.Paused)) { play.Resume(); } if (play.State.Equals(KStudioPlaybackState.Error)) { throw new InvalidOperationException("KStudioPlayback Error"); } } play.Stop(); } client.DisconnectFromService(); }
public void Evaluate(int SpreadMax) { if (FInputPlay.IsChanged) { if (FInputPlay[0]) { string xefFilePath = @FInputFilename[0]; if (!string.IsNullOrEmpty(xefFilePath)) { doPlay = true; OneArgDelegate recording = new OneArgDelegate(this.PlayClip); recording.BeginInvoke(xefFilePath, null, null); } } else { if (playback != null) { playback.Stop(); } } } if (FInputPause.IsChanged && (playback != null)) { if (FInputPause[0]) { if ((playback.State == KStudioPlaybackState.Playing)) { playback.Pause(); } } else { if ((playback.State == KStudioPlaybackState.Paused)) { playback.Resume(); } } } if (FInputStep[0]) { if ((playback.State == KStudioPlaybackState.Playing)) { playback.Pause(); } playback.StepOnce(); } if (FInputSeek.IsChanged && (playback != null)) { TimeSpan seekTime = TimeSpan.FromSeconds(FInputSeek[0]); playback.Pause(); playback.SeekByRelativeTime(seekTime); playback.Resume(); } if (playback != null) { FRecordDuration[0] = playback.CurrentRelativeTime.TotalSeconds; FRecord[0] = playback.State.ToString(); } }