/// <summary> /// Gets the playback duration of the current media item. /// </summary> /// <param name="mediaPlayer">A valid IMFPMediaPlayer 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 IMFPMediaPlayer mediaPlayer, out TimeSpan durationValue) { if (mediaPlayer == null) { throw new ArgumentNullException("mediaPlayer"); } using (PropVariant result = new PropVariant()) { HResult hr = mediaPlayer.GetDuration(Guid.Empty, result); durationValue = hr.Succeeded() ? TimeSpan.FromTicks((long)result.GetULong()) : default(TimeSpan); return(hr); } }