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();
            }
        }
Ejemplo n.º 2
0
        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();
            }
        }