/// <summary> /// Creates a media item from an object. /// </summary> /// <param name="mediaPlayer">A valid IMFPMediaPlayer instance.</param> /// <param name="mediaSink">An instance of a byte streamIndex.</param> /// <param name="userData">Application-defined value to store in the media item.</param> /// <param name="mediaItem">Receives an instance of a IMFPMediaItem interface.</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 CreateMediaItemFromObject(this IMFPMediaPlayer mediaPlayer, IMFByteStream byteStream, IntPtr userData, out IMFPMediaItem mediaItem) { if (byteStream == null) { throw new ArgumentNullException("mediaSink"); } return(mediaPlayer.CreateMediaItemFromObject(byteStream, true, userData, out mediaItem)); }
/// <summary> /// Removes an effect that was added with the IMFPMediaPlayer.InsertEffect method. /// </summary> /// <param name="mediaPlayer">A valid IMFPMediaPlayer instance.</param> /// <param name="activate">The activation object used to create the MFT.</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 RemoveEffect(this IMFPMediaPlayer mediaPlayer, IMFActivate activate) { if (mediaPlayer == null) { throw new ArgumentNullException("mediaPlayer"); } return(mediaPlayer.RemoveEffect(activate)); }
/// <summary> /// Removes an effect that was added with the IMFPMediaPlayer.InsertEffect method. /// </summary> /// <param name="mediaPlayer">A valid IMFPMediaPlayer instance.</param> /// <param name="transform">The Media Foundation transform (MFT) previously added.</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 RemoveEffect(this IMFPMediaPlayer mediaPlayer, IMFTransform transform) { if (mediaPlayer == null) { throw new ArgumentNullException("mediaPlayer"); } return(mediaPlayer.RemoveEffect(transform)); }
/// <summary> /// Applies an audio or video effect to playback. /// </summary> /// <param name="mediaPlayer">A valid IMFPMediaPlayer instance.</param> /// <param name="activate">An activation object that creates an MFT.</param> /// <param name="optional"> /// <list type="bullet"> /// <item> /// <term>True</term> /// <description>The effect is optional. If the MFPlay player object cannot add the effect, it ignores the effect and continues playback.</description> /// </item> /// <item> /// <term>False</term> /// <description>The effect is required. If the MFPlay player object cannot add the effect, a playback error occurs.</description> /// </item> /// </list> /// </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 InsertEffect(this IMFPMediaPlayer mediaPlayer, IMFActivate activate, bool optional) { if (mediaPlayer == null) { throw new ArgumentNullException("mediaPlayer"); } return(mediaPlayer.InsertEffect(activate, optional)); }
/// <summary> /// Applies an audio or video effect to playback. /// </summary> /// <param name="mediaPlayer">A valid IMFPMediaPlayer instance.</param> /// <param name="transform">A Media Foundation transform (MFT) that implements the effect.</param> /// <param name="optional"> /// <list type="bullet"> /// <item> /// <term>True</term> /// <description>The effect is optional. If the MFPlay player object cannot add the effect, it ignores the effect and continues playback.</description> /// </item> /// <item> /// <term>False</term> /// <description>The effect is required. If the MFPlay player object cannot add the effect, a playback error occurs.</description> /// </item> /// </list> /// </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 InsertEffect(this IMFPMediaPlayer mediaPlayer, IMFTransform transform, bool optional) { if (mediaPlayer == null) { throw new ArgumentNullException("mediaPlayer"); } return(mediaPlayer.InsertEffect(transform, optional)); }
/// <summary> /// Sets the playback position. /// </summary> /// <param name="mediaPlayer">A valid IMFPMediaPlayer instance.</param> /// <param name="positionValue">New playback position.</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 SetPosition(this IMFPMediaPlayer mediaPlayer, TimeSpan positionValue) { if (mediaPlayer == null) { throw new ArgumentNullException("mediaPlayer"); } using (PropVariant value = new PropVariant(positionValue.Ticks)) { return(mediaPlayer.SetPosition(Guid.Empty, value)); } }
/// <summary> /// Gets the current playback position. /// </summary> /// <param name="mediaPlayer">A valid IMFPMediaPlayer instance.</param> /// <param name="durationValue">Receives the playback position.</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 GetPosition(this IMFPMediaPlayer mediaPlayer, out TimeSpan positionValue) { if (mediaPlayer == null) { throw new ArgumentNullException("mediaPlayer"); } using (PropVariant result = new PropVariant()) { HResult hr = mediaPlayer.GetPosition(Guid.Empty, result); positionValue = hr.Succeeded() ? TimeSpan.FromTicks((long)result.GetULong()) : default(TimeSpan); return(hr); } }
/// <summary> /// Creates a new instance of the MFPlay player object. /// </summary> /// <param name="url">A string that contains the URL of a media file to open.</param> /// <param name="startPlayback">If true, playback starts automatically. If false, playback does not start until the application calls IMFMediaPlayer.Play.</param> /// <param name="creationOptions">Bitwise OR of zero of more flags from the MFP_CREATION_OPTIONS enumeration.</param> /// <param name="callback">An instance of the IMFPMediaPlayerCallback interface of a callback object, implemented by the application.</param> /// <param name="hWnd">A handle to a window where the video will appear. For audio-only playback, this parameter can be IntPtr.Zero.</param> /// <param name="mediaPlayer">Receives an instance of to the IMFPMediaPlayer interface.</param> /// <returns></returns> public static HResult CreateMediaPlayer(string url, bool startPlayback, MFP_CREATION_OPTIONS creationOptions, IMFPMediaPlayerCallback callback, IntPtr hWnd, out IMFPMediaPlayer mediaPlayer) { return(MFExtern.MFPCreateMediaPlayer(url, startPlayback, creationOptions, callback, hWnd, out mediaPlayer)); }
public static extern int MFPCreateMediaPlayer(string pwszURL, bool fStartPlayback, uint creationOptions, IMFPMediaPlayerCallback pCallback, IntPtr hWnd, out IMFPMediaPlayer ppMediaPlayer);