protected void StartPlayback()
        {
            HResult hr = m_pSession.Start(Guid.Empty, new PropVariant());

            if (hr == HResult.S_OK)
            {
                mPlayPauseBtn.IsEnabled = true;

                mImageBtn.Source = new BitmapImage(new Uri("pack://application:,,,/WPFMediaFoundationPlayer;component/Images/pause.png", UriKind.Absolute));

                mIsPlaying = true;

                mPresentationClock = null;

                m_pSession.GetClock(out mPresentationClock);

                mTickTimer.Start();

                mIsSeek = false;
            }

            MFError.ThrowExceptionForHR(hr);

            //m_pSession.
        }
Example #2
0
        /// <summary>
        /// Start play Media
        /// </summary>
        protected void StartPlayback()
        {
            TRACE("Media::StartPlayback");
            Debug.Assert(m_pSession != null);

            m_pSession.Start(Guid.Empty, new PropVariant());
        }
Example #3
0
        /// <summary>
        /// Plays the media
        /// </summary>
        public virtual void Play()
        {
            VerifyAccess();

            if (m_pSession != null)
            {
                m_pSession.Start(Guid.Empty, new PropVariant());
            }
        }
        /// <summary>
        /// Starts playback.
        /// </summary>
        /// <param name="StartedPosition">Where to start playback,in second.</param>
        public void Play(long StartedPosition)
        {
            if (!IsPrepared)
            {
                throw new InvalidOperationException("This player is still loading.");
            }
            if (StartedPosition > Duration)
            {
                throw new ArgumentException("Invaalid time.");
            }
            PropVariant pos = new PropVariant
            {
                vt   = (short)VarEnum.VT_I8,
                hVal = StartedPosition * 10000000,
            };

            m_Session.Start(Guid.Empty, pos);
        }
Example #5
0
        public void PlayFromBegining()
        {
            if (m_Session == null)
            {
                throw new InvalidOperationException("This player hasn't initialized yet");
            }
            if (!Prepared)
            {
                throw new InvalidOperationException("This player is still loading.");
            }
            PropVariant pos = new PropVariant()
            {
                vt   = (short)VarEnum.VT_I8,
                hVal = 0
            };

            m_Session.Start(Guid.Empty, ref pos);
            PlaybackState = PlaybackState.Playing;
        }
Example #6
0
        ////////////////////////////////////////////////////////////////////////////////////////
        //  Name: CPlayer::Play (Public)
        //  Description:
        //      Starts the media session with the current topology
        ///////////////////////////////////////////////////////////////////////////////////////////

        public HResult Play()
        {
            Debug.WriteLine("\nCPlayer::Play");

            HResult hr = 0;

            try
            {
                // Create the starting position parameter
                PropVariant var = new PropVariant();

                hr = m_pMediaSession.Start(Guid.Empty, var);
                MFError.ThrowExceptionForHR(hr);
            }
            catch (Exception e)
            {
                hr = (HResult)Marshal.GetHRForException(e);
            }

            return(hr);
        }
        /// <summary>
        /// Starts the Media Session.
        /// </summary>
        /// <param name="mediaSession">A valid IMFMediaSession instance.</param>
        /// <param name="startPosition">The starting position for playback.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult Start(this IMFMediaSession mediaSession, TimeSpan startPosition)
        {
            if (mediaSession == null)
            {
                throw new ArgumentNullException("mediaSession");
            }

            using (PropVariant start = new PropVariant(startPosition.Ticks))
            {
                return(mediaSession.Start(Guid.Empty, start));
            }
        }
Example #8
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Starts the copy of the media data
        /// </summary>
        /// <history>
        ///    01 Nov 18  Cynic - Originally Written
        /// </history>
        private void StartFileCopy()
        {
            LogMessage("StartFileCopy called");

            if (mediaSession == null)
            {
                LogMessage("StartFileCopy Failed.  mediaSession == null");
                return;
            }

            // this is what starts the data moving through the pipeline
            HResult hr = mediaSession.Start(Guid.Empty, new PropVariant());

            if (hr != HResult.S_OK)
            {
                throw new Exception("StartFileCopy call to mediaSession.Start failed. Err=" + hr.ToString());
            }
        }
        private static HResult RunMediaSession(IMFMediaSession mediaSession)
        {
            HResult hr = S_OK;

            bool receiveSessionEvent = true;

            while (receiveSessionEvent)
            {
                HResult        hrStatus   = S_OK;
                IMFMediaEvent  mediaEvent = null;
                MediaEventType eventType  = MediaEventType.MEUnknown;

                MFTopoStatus topoStatus = MFTopoStatus.Invalid;

                hr = mediaSession.GetEvent(MFEventFlag.None, out mediaEvent);

                if (Succeeded(hr))
                {
                    hr = mediaEvent.GetStatus(out hrStatus);
                }

                if (Succeeded(hr))
                {
                    hr = mediaEvent.GetType(out eventType);
                }

                if (Succeeded(hr) && Succeeded(hrStatus))
                {
                    switch (eventType)
                    {
                    case MediaEventType.MESessionTopologySet:
                        Debug.WriteLine("MediaSession:TopologySetEvent");
                        break;

                    case MediaEventType.MESessionTopologyStatus:
                        Debug.WriteLine("MediaSession:TopologStatusEvent");

                        hr = mediaEvent.GetUINT32(MF_EVENT_TOPOLOGY_STATUS, out int topoStatusInt);

                        if (Succeeded(hr))
                        {
                            topoStatus = (MFTopoStatus)topoStatusInt;
                            switch (topoStatus)
                            {
                            case MFTopoStatus.Ready:
                                Debug.WriteLine("MediaSession:TopologyStatus: MFTopoStatus.Ready");
                                hr = mediaSession.Start();
                                break;

                            default:
                                Debug.WriteLine("MediaSession:TopologyStatus: MFTopoStatus." + topoStatus);
                                break;
                            }
                        }
                        break;

                    case MediaEventType.MESessionClosed:
                        Debug.WriteLine("MediaSession:SessionClosedEvent");
                        receiveSessionEvent = false;
                        break;

                    case MediaEventType.MESessionStopped:
                        Debug.WriteLine("MediaSession:SesssionStoppedEvent");
                        hr = mediaSession.Stop();
                        break;

                    default:
                        Debug.WriteLine("MediaSession:Event: " + eventType);
                        break;
                    }

                    mediaEvent = null;

                    if (Failed(hr) || Failed(hrStatus))
                    {
                        receiveSessionEvent = false;
                    }
                }
            }

            return(hr);
        }