Exemple #1
0
        private void PlayWithAvsPlayer(string scriptPath)
        {
            avsPlayer = new AviSynthPlayer(this);
            avsPlayer.EnableAudio = Settings.PictureViewAudio;
            avsPlayer.AllowDropFrames = Settings.PictureViewDropFrames;
            avsPlayer.PlayerError += new AvsPlayerError(AvsPlayerError);

            avsPlayer.Open(scriptPath);
            if (avsPlayer.IsError)
                return;

            IsAviSynthError = false;
            IsAudioOnly = !avsPlayer.HasVideo;
            avsPlayer.Volume = VolumeSet;

            if (!IsAudioOnly)
            {
                int frame = 0;
                if (mediaload == MediaLoad.load)
                {
                    //Новое открытие (сразу Play или переход на середину)
                    if (Settings.AfterImportAction == Settings.AfterImportActions.Play)
                        currentState = PlayState.Running;
                    else if (Settings.AfterImportAction == Settings.AfterImportActions.Middle)
                        frame = avsPlayer.TotalFrames / 2;
                }
                else
                {
                    //Ограничиваем кол-во кадров (могло измениться, например, после Trim`а)
                    frame = (avsFrame > avsPlayer.TotalFrames) ? avsPlayer.TotalFrames : avsFrame;
                }

                avsPlayer.SetFrame(frame);
                if (avsPlayer.IsError)
                    return;

                avsPlayer.PlayerFinished += new AvsPlayerFinished(AvsPlayerFinished);
                avsPlayer.AvsStateChanged += new AvsState(AvsStateChanged);
                Pic.Source = avsPlayer.BitmapSource;
                Pic.Visibility = Visibility.Visible;

                if (currentState == PlayState.Running)
                {
                    //Запуск сразу с Play
                    avsPlayer.Play();
                    SetPauseIcon();
                }
                else
                {
                    //Запуск на паузе
                    avsPlayer.Pause();
                    this.currentState = PlayState.Paused;
                    avsPlayer.UnloadAviSynth();
                }

                MoveVideoWindow();

                avsFrame = frame;                                                                     //Текущий кадр
                fps = avsPlayer.Framerate;                                                            //fps скрипта
                slider_pos.Maximum = TimeSpan.FromSeconds(avsPlayer.TotalFrames / fps).TotalSeconds;  //Устанавливаем максимум для ползунка

                //Текущий кадр и общая продолжительность клипа
                textbox_frame.Text = frame + "/" + (total_frames = avsPlayer.TotalFrames.ToString());
                textbox_duration.Text = TimeSpan.Parse(TimeSpan.FromSeconds(avsPlayer.TotalFrames / fps).ToString().Split('.')[0]).ToString();
            }
            else
            {
                PreviewError("NO VIDEO", Brushes.Gainsboro);
            }
        }
Exemple #2
0
        private void CloseClip()
        {
            try
            {
                //Останавливаем таймер обновления позиции
                if (timer != null) timer.Stop();

                //DirectShow
                if (this.graphBuilder != null && this.VideoElement.Source == null)
                {
                    int hr = 0;

                    // Stop media playback
                    if (this.mediaControl != null)
                        hr = this.mediaControl.Stop();

                    // Free DirectShow interfaces
                    CloseInterfaces();

                    //EVR
                    if (VHost != null)
                    {
                        VHost.Dispose();
                        VHost = null;
                        VHandle = IntPtr.Zero;
                        VHostElement.Child = null;
                        VHostElement.Visibility = Visibility.Collapsed;
                        VHostElement.Width = VHostElement.Height = 0;
                        VHostElement.Margin = new Thickness(0);
                    }

                    // No current media state
                    if (mediaload != MediaLoad.update)
                        this.currentState = PlayState.Init;
                }

                //MediaBridge
                if (this.VideoElement.Source != null)
                {
                    VideoElement.Stop();
                    VideoElement.Close();
                    VideoElement.Source = null;
                    VideoElement.Visibility = Visibility.Collapsed;
                    VideoElement.Width = VideoElement.Height = 0;
                    VideoElement.Margin = new Thickness(0);

                    if (mediaload != MediaLoad.update)
                        this.currentState = PlayState.Init;

                    if (this.graphBuilder != null)
                    {
                        while (Marshal.ReleaseComObject(this.graphBuilder) > 0) ;
                        this.graphBuilder = null;
                        if (this.graph != null)
                        {
                            while (Marshal.ReleaseComObject(this.graph) > 0) ;
                            this.graph = null;
                        }
                        //Marshal.ReleaseComObject(this.graphBuilder);
                        //this.graphBuilder = null;
                        //Marshal.ReleaseComObject(this.graph);
                        //this.graph = null;
                        GC.Collect();
                    }

                    Thread.Sleep(100);
                    string url = "MediaBridge://MyDataString";
                    MediaBridge.MediaBridgeManager.UnregisterCallback(url);
                }

                //ScriptView
                if (script_box.Visibility != Visibility.Collapsed)
                {
                    script_box.Clear();
                    script_box.Visibility = Visibility.Collapsed;
                    this.currentState = PlayState.Init;
                }

                //AviSynthPlayer (PictureView)
                if (avsPlayer != null)
                {
                    avsPlayer.Abort();
                    avsPlayer.Close();
                    avsPlayer = null;

                    Pic.Source = null;
                    Pic.Visibility = Visibility.Collapsed;
                    Pic.Margin = new Thickness(0);
                    Pic.Width = Pic.Height = 0;

                    if (mediaload != MediaLoad.update)
                        this.currentState = PlayState.Init;
                }

                //Окно ошибок
                if (ErrBox.Visibility != Visibility.Collapsed)
                {
                    ErrBox.Child = null;
                    ErrBox.Visibility = Visibility.Collapsed;
                }
            }
            catch (Exception ex)
            {
                ErrorException("CloseClip: " + ex.Message, ex.StackTrace);
            }

            //update titles
            textbox_name.Text = textbox_frame.Text = "";
            textbox_time.Text = textbox_duration.Text = "00:00:00";
            progress_top.Width = slider_pos.Value = 0.0;

            SetPlayIcon();
        }