OfficeTips Home || VBA Section || General Section || Download Section || Privacy Policy

Media Format and Bookmarks

The new MediaFormat object associated with shapes is really cool. It offers everything that you could need to gather information about the inserted media shape. The code below also shows how to add a bookmark trigger. MediaFormat object has also two methods to resample audio and video in the presentation - Resample and ResampleFromProfile - which allows us to tap into the profile settings available in the compress media drop down.

See also: How to use msoAnimEffectPlayFromBookmark

Supported versions: PowerPoint 2010


Sub MediaInfo()
Dim oShp As Shape
Dim oMBK As MediaBookmark
Dim I As Integer

' Assumes that this shape is either inserted video or audio.

Set oShp = ActiveWindow.Selection.ShapeRange(1)

' Note: Online video is also flagged as mediatype shape
' but it fails on all these properties, only SourceFullName property works
' See *Linked info

If oShp.Type = msoMedia Then
    Debug.Print "Lenght: " & oShp.MediaFormat.Length
    Debug.Print "Start Point: " & oShp.MediaFormat.StartPoint
    Debug.Print "End Point: " & oShp.MediaFormat.EndPoint

    Debug.Print "Fade In Duration: " & oShp.MediaFormat.FadeInDuration
    Debug.Print "Fade Out Duration: " & oShp.MediaFormat.FadeOutDuration

    Debug.Print "Is Embedded: " & oShp.MediaFormat.IsEmbedded
    Debug.Print "Is linked: " & oShp.MediaFormat.IsLinked

    If oShp.MediaFormat.IsLinked Then
        Debug.Print "Movie Source: " & oShp.LinkFormat.SourceFullName '*Linked info
    End If

    Debug.Print "Volume: " & oShp.MediaFormat.Volume
    Debug.Print "Muted: " & oShp.MediaFormat.Muted
    Debug.Print "Audio Compression Type: " & oShp.MediaFormat.AudioCompressionType
    Debug.Print "Audio Audio Sampling Rate: " & oShp.MediaFormat.AudioSamplingRate

    ' Applicable only to video types
    '=====================================================================================
    If oShp.MediaType = ppMediaTypeMovie Then
        Debug.Print "Video Compression Type: " & oShp.MediaFormat.VideoCompressionType
        Debug.Print "Video Frame Rate: " & oShp.MediaFormat.VideoFrameRate

        ' Set poster frame
        Call oShp.MediaFormat.SetDisplayPicture(1000)
        ' Set poster frame from external image.
        Call oShp.MediaFormat.SetDisplayPictureFromFile("C:\Users\Shyam\Pictures\mvp.jpg")

        Debug.Print "Height: " & oShp.MediaFormat.SampleHeight
        Debug.Print "Width: " & oShp.MediaFormat.SampleWidth

        ' Movie Container Shape
        Debug.Print oShp.AutoShapeType
    End If

    '=====================================================================================

    ' It is possible to create bookmarks in the audio/video timeline for the media shape.
    ' You can then trigger an animation when the media hits the bookmark during playback
    ' Pretty cool, eh? 
    ' See the subroutine below this one to see how you can assign a bookmark trigger

    '=====================================================================================

        ' Add media bookmark, position is in milliseconds
        ' Note: Can't assign 2 bookmarks at the same point in the timeline.
        ' Generates error if specified duration is greater than movie duration
        ' Generates error if specified bookmark already exists on the timeline


        Call oShp.MediaFormat.MediaBookmarks.Add(4000, "Bookmark A")
        Call oShp.MediaFormat.MediaBookmarks.Add(8000, "Bookmark B")
        Call oShp.MediaFormat.MediaBookmarks.Add(9000, "Bookmark C")

        'Count the number of bookmarks
        Debug.Print "Bookmark count: " & oShp.MediaFormat.MediaBookmarks.Count
        
        'Retrieve info from the 1st bookmark
        For I = 1 To oShp.MediaFormat.MediaBookmarks.Count
                Set oMBK = oShp.MediaFormat.MediaBookmarks(I)
                Debug.Print oMBK.Index, "Name: " & oMBK.Name, "Position: " & oMBK.Position
        Next

        'Delete all the bookmarks
        For I = oShp.MediaFormat.MediaBookmarks.Count To 1 Step -1
                Set oMBK = oShp.MediaFormat.MediaBookmarks(I)
                oMBK.Delete
        Next
        End If
End Sub


Sub AddBookmarkTrigger()
Dim oShp As Shape         ' Shape with animation that needs to be triggered via bookmark
Dim oShpMovie As Shape    ' Media shape

'Assumes that we have a media shape with 'Bookmark 1' on slide 1 of the presentation
With ActivePresentation.Slides(1)
        Set oShpMovie = .Shapes(1)
        Set oShp = .Shapes(2)
        ' Assign an trigger to shape
        ' if no bookmark name is specified, it will default to 1st. If no bookmark exists then it fails
        Call .TimeLine.InteractiveSequences.Add.AddTriggerEffect(oShp, msoAnimEffectPathCircle, _   
                                msoAnimTriggerOnMediaBookmark, oShpMovie, "Bookmark 1")
End With

End Sub

 

 


Copyright 1999-2018 (c) Shyam Pillai. All rights reserved.