Microsoft DirectX 8.0

MediaDet Object

Retrieves information about a media file, such as the number of streams and the type, duration, and frame rate of each stream. This interface also contains methods for retrieving poster frames from a video stream.

To obtain information about a file, perform the following steps:

  1. Create a new instance of the MediaDet object.
  2. Set the Filename property to specify the name of the source file.
  3. Retrieve the OutputStreams property to obtain the number of output streams in the source.
  4. Set the CurrentStream property to specify a particular stream.
  5. Retrieve any of the following properties: StreamType, StreamMediaType, StreamLength, or FrameRate.

To retrieve poster frames, call WriteBitmapBits. This method puts the MediaDet object into a new mode, called bitmap grab mode. The informational methods described previously do not work in this mode. Therefore, obtain any information you need before retrieving poster frames, or else create new instances of the MediaDet object for each stream.

The following code example shows how to use this object:

Dim Det As New MediaDet
Const VideoGUID As String = "{73646976-0000-0010-8000-00AA00389B71}"
bFoundVidStream = False

Det.FileName = "C:\Media\Example.avi"

' Look for a video stream.
For i = 0 To Det.OutputStreams - 1
    Det.CurrentStream = i
    StreamType = Det.StreamTypeB
    If StrComp(StreamType, VideoGUID, vbTextCompare) = 0 Then
        bFoundVidStream = True
        Exit For
    End If
Next

If bFoundVidStream Then
    ' Update the label with the duration.
    VideoInfo.Caption = Det.FileName + ": " + Str(Det.StreamLength) + " seconds"
    
    ' Load a poster frame.
    TempFile = "C:\Temp.bmp"
    Preview.ScaleMode = vbPixels  ' Scale twips to pixels.
    Det.WriteBitmapBits 0, Preview.ScaleWidth, Preview.ScaleHeight, TempFile
    Preview.Picture = LoadPicture(TempFile)
End If

Properties

CurrentStreamStream number currently used by the MediaDet object.
FilenameName of the source file currently used by the MediaDet object.
FilterNot supported for Visual Basic.
OutputStreamsNumber of output streams contained in the media source.
FrameRateFrame rate of the current stream, in frames per second.
StreamLengthDuration of the current stream, in seconds.
StreamMediaTypeNot supported for Visual Basic.
StreamTypeNot supported for Visual Basic.
StreamTypeBString representing the GUID of the media type for the current stream.

Methods

EnterBitmapGrabModeSwitches the MediaDet object to bitmap grab mode and seeks the filter graph to a specified time.
GetBitmapBitsNot supported for Visual Basic.
GetSampleGrabberNot supported for Visual Basic.
WriteBitmapBitsRetrieves a poster frame at the specified media time and writes it to a file.

CurrentStream Property (MediaDet Object)

MediaDet Object

Stream number currently used by the MediaDet object. Read/write.

Syntax

object.CurrentStream As Long

Parts

object
Object expression that evaluates to a MediaDet object.

Filename Property (MediaDet Object)

MediaDet Object

Name of the source file currently used by the MediaDet object. Read/write.

Syntax

object.Filename As String

Parts

object
Object expression that evaluates to a MediaDet object.

Filter Property (MediaDet Object)

MediaDet Object

Not supported for Visual Basic.

Syntax

object.Filter As Unknown

FrameRate Property (MediaDet Object)

MediaDet Object

Frame rate of the current stream, in frames per second. Read-only.

Syntax

object.FrameRate As Double

Parts

object
Object expression that evaluates to a MediaDet object.

Remarks

The stream must be a video stream. This property is not valid for ASF files. The property is not valid if the MediaDet object is in bitmap grab mode (see EnterBitmapGrabMode).

Before retrieving this property, set the Filename and CurrentStream properties.

OutputStreams Property (MediaDet Object)

MediaDet Object

Number of output streams contained in the media source. Read-only.

Syntax

object.OutputStreams As Long

Parts

object
Object expression that evaluates to a MediaDet object.

Remarks

Before retrieving this property, set the Filename property.

This property is not valid if the MediaDet object is in bitmap grab mode (see EnterBitmapGrabMode).

StreamLength Property (MediaDet Object)

MediaDet Object

Duration of the current stream, in seconds.

Syntax

object.StreamLength As Double

Parts

object
Object expression that evaluates to a MediaDet object.

Remarks

Before retrieving this property, set the Filename and CurrentStream properties.

This property is not valid if the MediaDet object is in bitmap grab mode (see EnterBitmapGrabMode).

StreamMediaType Property (MediaDet Object)

MediaDet Object

Not supported for Visual Basic.

Syntax

object.get_StreamMediaType As _AMMediaType

StreamType Property (MediaDet Object)

MediaDet Object

Not supported for Visual Basic.

Syntax

object.StreamType As GUID

StreamTypeB Property (MediaDet Object)

MediaDet Object

String representing the GUID of the media type for the current stream. Read-only.

Syntax

object.StreamTypeB As String

Parts

object
Object expression that evaluates to a MediaDet object.

Remarks

The string formatted like the following: {73647561-0000-0010-8000-00AA00389B71}

Before retrieving this property, set the Filename and CurrentStream properties. This property is not valid if the MediaDet object is in bitmap grab mode (see EnterBitmapGrabMode).

EnterBitmapGrabMode Method (MediaDet Object)

MediaDet Object

Switches the MediaDet object to bitmap grab mode and seeks the filter graph to a specified time.

Syntax

object.EnterBitmapGrabMode(
    SeekTime As Double
)

Parts

object
Object expression that evaluates to a MediaDet object.
SeekTime
Time, in seconds, to which the graph seeks.

Error Codes

If the method fails, an error is raised, and Err.Number can be set to one of the following values:

E_INVALIDARGInvalid argument.
VFW_E_INVALIDMEDIATYPEFile does not have a video stream.
VFW_E_TIME_EXPIREDCould not seek.

Remarks

Before calling this method, set the Filename and CurrentStream properties.

This method inserts the Sample Grabber filter into the filter graph. Once the MediaDet object enters bitmap grab mode, the various informational methods in MediaDet do not work.

The GetBitmapBits or WriteBitmapBits methods also put the object into bitmap grab mode.

GetBitmapBits Method (Media Object)

MediaDet Object

Not supported for Visual Basic.

Syntax

object.GetBitmapBits(
    StreamTime As Double, 
    pBufferSize As Long, 
    pBuffer As Byte, 
    Width As Long, 
    Height As Long
)

GetSampleGrabber Method (MediaDet Object)

MediaDet Object

Not supported for Visual Basic.

Syntax

object.GetSampleGrabber( 
    ppVal As SampleGrabber
)

WriteBitmapBits Method (MediaDet Object)

MediaDet Object

Retrieves a poster frame at the specified media time and writes it to a file.

Syntax

object.WriteBitmapBits(
    StreamTime As Double, 
    Width As Long, 
    Height As Long, 
    Filename As String
)

Parts

object
Object expression that evaluates to a MediaDet object.
StreamTime
Time at which to retrieve the poster frame, in seconds.
Width
Width of the poster frame image, in pixels.
Height
Height of the poster frame image, in pixels.
Filename
Path of the file in which to save the poster frame. If the file already exists, this method overwrites it.

Error Codes

If the method fails, an error is raised, and Err.Number can be set to one of the following values:

E_NOINTERFACECould not add the Sample Grabber filter to the graph.
E_FAILFailure.
E_OUTOFMEMORYInsufficient memory.
E_UNEXPECTEDUnexpected error.
STG_E_ACCESSDENIEDCannot overwrite file.
VFW_E_INVALIDMEDIATYPEInvalid media type.

Remarks

Before calling this method, set the Filename and CurrentStream properties.

This method puts the MediaDet object into bitmap grab mode. Once this method has been called, the various stream information methods in IMediaDet do not work, unless you create a new instance of the object.