コード例 #1
0
        /// <summary>
        /// Sets a media sink for the media item. A media sink is an object that consumes the data from one or more streams.
        /// </summary>
        /// <param name="mediaItem">A valid IMFPMediaItem instance.</param>
        /// <param name="streamIndex">Zero-based index of a streamIndex on the media source.</param>
        /// <param name="activate">An instance of an activation object that creates the media sink.</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 SetStreamSink(this IMFPMediaItem mediaItem, int streamIndex, IMFActivate activate)
        {
            if (mediaItem == null)
            {
                throw new ArgumentNullException("mediaItem");
            }

            return(mediaItem.SetStreamSink(streamIndex, activate));
        }
コード例 #2
0
        /// <summary>
        /// Sets the start and stop time for the media item.
        /// </summary>
        /// <param name="mediaItem">A valid IMFPMediaItem instance.</param>
        /// <param name="startValue">Start position.</param>
        /// <param name="stopValue">Stop 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 SetStartStopPosition(this IMFPMediaItem mediaItem, TimeSpan startValue, TimeSpan stopValue)
        {
            if (mediaItem == null)
            {
                throw new ArgumentNullException("mediaItem");
            }

            using (PropVariant resultStart = new PropVariant(startValue.Ticks), resultStop = new PropVariant(stopValue.Ticks))
            {
                return(mediaItem.SetStartStopPosition(Guid.Empty, resultStart, Guid.Empty, resultStop));
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets the duration of the media item.
        /// </summary>
        /// <param name="mediaItem">A valid IMFPMediaItem instance.</param>
        /// <param name="durationValue">Receives the duration.</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 GetDuration(this IMFPMediaItem mediaItem, out TimeSpan durationValue)
        {
            if (mediaItem == null)
            {
                throw new ArgumentNullException("mediaItem");
            }

            using (PropVariant result = new PropVariant())
            {
                HResult hr = mediaItem.GetDuration(Guid.Empty, result);
                durationValue = hr.Succeeded() ? TimeSpan.FromTicks((long)result.GetULong()) : default(TimeSpan);

                return(hr);
            }
        }
コード例 #4
0
        /// <summary>
        /// Gets the start and stop times for the media item.
        /// </summary>
        /// <param name="mediaItem">A valid IMFPMediaItem instance.</param>
        /// <param name="startValue">Receives the start position.</param>
        /// <param name="stopValue">Receives the stop 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 GetStartStopPosition(this IMFPMediaItem mediaItem, out TimeSpan startValue, out TimeSpan stopValue)
        {
            if (mediaItem == null)
            {
                throw new ArgumentNullException("mediaItem");
            }

            using (PropVariant resultStart = new PropVariant(), resultStop = new PropVariant())
            {
                HResult hr = mediaItem.GetStartStopPosition(Guid.Empty, resultStart, Guid.Empty, resultStop);
                if (hr.Succeeded())
                {
                    startValue = TimeSpan.FromTicks((long)resultStart.GetULong());
                    stopValue  = TimeSpan.FromTicks((long)resultStop.GetULong());
                }
                else
                {
                    startValue = default(TimeSpan);
                    stopValue  = default(TimeSpan);
                }

                return(hr);
            }
        }
コード例 #5
0
        /// <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));
        }