Ejemplo n.º 1
0
        public bool StopClip()
        {
            if (this.currentState == RadPlayState.Init)
            {
                SetLastError("There is nothing to stop");
                return(false);
            }

            if (this.mediaControl == null)
            {
                SetLastError("No funtionality for control of the playing is presented");
                return(false);
            }

            // Stop and reset postion to beginning
            if ((this.currentState == RadPlayState.Paused) || (this.currentState == RadPlayState.Running))
            {
                Check(this.mediaControl.Stop());

                // Seek to the beginning
                SetCurrentPosition(0);

                // Display the first frame to indicate the reset condition
                Check(this.mediaControl.Pause());

                this.currentState = RadPlayState.Stopped;
            }

            return(true);
        }
Ejemplo n.º 2
0
        public bool CloseClip()
        {
            bool res = true;

            // Don't report closing errors if the state is Init - in most cases there is nothing to close
            // so errors while closing will occur.
            // Anyway even the state is Init we will try to close all open interfaces - we could be in
            // some faulty situation...
            bool dontReportErrors = this.currentState == RadPlayState.Init;

            // Stop media playback
            if (this.mediaControl == null)
            {
                SetLastError("No funtionality for control of the playing is presented");
                res = false;
            }
            else
            {
                res = Check(this.mediaControl.Stop());
            }

            // Clear global flags
            this.currentState = RadPlayState.Stopped;

            // Free DirectShow interfaces
            if (!CloseInterfaces(false))
            {
                res = false;
            }

            this.hasAudio = false;
            this.hasVideo = false;

            // No current media state
            this.currentState = RadPlayState.Init;

            if (dontReportErrors)
            {
                ClearLastError();
                res = true;
            }

            return(res);
        }
Ejemplo n.º 3
0
        public bool PauseClip()
        {
            if (this.currentState == RadPlayState.Init)
            {
                SetLastError("There is nothing to pause");
                return(false);
            }

            if (this.mediaControl == null)
            {
                SetLastError("No funtionality for control of the playing is presented");
                return(false);
            }

            if (!Check(this.mediaControl.Pause()))
            {
                return(false);
            }

            this.currentState = RadPlayState.Paused;
            return(true);
        }
Ejemplo n.º 4
0
        public bool PlayClip()
        {
            if (this.currentState == RadPlayState.Init)
            {
                SetLastError("There is nothing to play");
                return(false);
            }

            if (this.mediaControl == null)
            {
                SetLastError("No funtionality for control of the playing is presented");
                return(false);
            }

            // Run the graph to play the media file
            if (!Check(this.mediaControl.Run()))
            {
                return(false);
            }

            this.currentState = RadPlayState.Running;
            return(true);
        }
Ejemplo n.º 5
0
        public bool OpenClip(string fileName)
        {
            if (fileName == string.Empty)
            {
                return(false);
            }

            CloseClip();
            ClearLastError();
            deleteTempFile = true; // From now on CloseClip() will delete the file if it is temporary

            this.graphBuilder = (IGraphBuilder) new FilterGraph();

            // Have the graph builder construct its the appropriate graph automatically
            if (!Check(this.graphBuilder.RenderFile(fileName, null)))
            {
                return(false);
            }

            // QueryInterface for DirectShow interfaces
            this.mediaControl  = this.graphBuilder as IMediaControl;
            this.mediaEventEx  = this.graphBuilder as IMediaEventEx;
            this.mediaSeeking  = this.graphBuilder as IMediaSeeking;
            this.mediaPosition = this.graphBuilder as IMediaPosition;

            // Query for video interfaces, which may not be relevant for audio files
            this.videoWindow = this.graphBuilder as IVideoWindow;
            this.basicVideo  = this.graphBuilder as IBasicVideo;

            // Query for audio interfaces, which may not be relevant for video-only files
            this.basicAudio = this.graphBuilder as IBasicAudio;

            // Is this an audio-only file (no video component)?
            CheckVisibility();

            // Have the graph signal event via window callbacks for performance
            if (!Check(this.mediaEventEx.SetNotifyWindow(this.Handle, WMGraphNotify, IntPtr.Zero)))
            {
                CloseClipNoError();
                return(false);
            }

            if (this.hasVideo)
            {
                // Setup the video window
                if (!Check(this.videoWindow.put_Owner(this.Handle)))
                {
                    CloseClipNoError();
                    return(false);
                }

                if (!Check(this.videoWindow.put_WindowStyle(
                               WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren)))
                {
                    CloseClipNoError();
                    return(false);
                }

                int videoWidth, videoHeight;
                if (this.basicVideo != null &&
                    this.basicVideo.GetVideoSize(out videoWidth, out videoHeight) != DsResults.E_NoInterface)
                {
                    this.originalVideoSize = new Size(videoWidth, videoHeight);
                }
                else
                {
                    this.originalVideoSize = Size.Empty;
                }

                if (!this.originalVideoSize.IsEmpty)
                {
                    this.ClientSize = this.originalVideoSize;

                    Check(this.videoWindow.SetWindowPosition(0, 0,
                                                             this.originalVideoSize.Width, this.originalVideoSize.Height));
                }

                GetFrameStepInterface();
            }

#if DEBUG
            rot = new DsROTEntry(this.graphBuilder);
#endif

            // Reset time format
            if (this.mediaSeeking != null)
            {
                Guid currentTimeFormat;
                if (Check(this.mediaSeeking.GetTimeFormat(out currentTimeFormat)))
                {
                    if (currentTimeFormat != TimeFormat.MediaTime)
                    {
                        Check(this.mediaSeeking.SetTimeFormat(TimeFormat.MediaTime));
                    }
                }
            }

            this.duartion = GetDuration();

            this.currentState = RadPlayState.Stopped;
            return(true);
        }