Share via


Adding Multimedia to a PowerPoint 2003 Presentation

 

Andrew May
Microsoft Corporation

April 2004

Applies to:
    Microsoft® Office PowerPoint® 2003
    Microsoft PowerPoint 2002

Summary: Learn how Microsoft Office PowerPoint 2003 employs Microsoft Windows multimedia technology to play media files, the best approaches for working with media in presentations, and the advantages of inserting media files into presentation as objects that PowerPoint recognizes as movies and sounds. (9 printed pages)

Contents

Introduction
Inserting Audio and Video Files as Media Objects
Inserting Media Files as OLE Objects
Conclusion

Introduction

One of the strengths of Microsoft® Office PowerPoint® 2003 is that it enables users to incorporate sounds and movies to create multimedia presentations that have impact. To create the most robust, effective multimedia presentation experience, you need to understand how Microsoft PowerPoint 2002 and Microsoft Office PowerPoint 2003 insert media files, and the best way to add such files to PowerPoint and control their behavior programmatically.

Inserting Audio and Video Files as Media Objects

There are two ways to add a media file to your presentation: as a media object, or as an OLE object. The easiest and most flexible method is to add the file as a media object. We'll discuss how to insert a media file as a media object, and the advantages of doing so, and then cover how to insert the media file as an OLE object.

Adding the file as a media object ensures that PowerPoint recognizes the file as a piece of multimedia; this, in turn, enables you to take advantage of all the built-in support and customization PowerPoint provides for dealing with sound and video files. PowerPoint chooses the appropriate media player to play the file. In addition, you can assign certain behaviors for media objects in PowerPoint. For both audio and video files, you can loop playing the media file until either the next media file starts, the user clicks the slide, or a slide transition occurs. For video files, you can also automatically rewind the video to the first frame once it has finished playing.

Use the Shapes.AddMediaObject method to add a media file programmatically to the selected slide. The method adds the file as a Shape object whose Type property is ppMedia. To determine whether the shape represents an audio or video file, use the Shape.MediaType property. Use this method for both sound and video media files.

In the PowerPoint user interface, on the Insert menu, point to Movies and Sounds, and then click Movie From File.

Once you insert the media object, you can use the properties of the PlaySettings object to specify the custom behavior you want to assign the media file.

The following example inserts an .avi file as a media object, and then inserts an animation effect into the main animation sequence for the slide. It also specifies custom behavior for the .avi file during the animation.

Dim shpMovie As Shape
Dim effMovie As Effect

With ActivePresentation.Slides(7)
    Set shpMovie = .Shapes.AddMediaObject _
        (FileName:="C:movie.avi", _
        Left:=100, _
        Top:=100)
    With .TimeLine.MainSequence
        Set effMovie = .AddEffect(Shape:=shpMovie, _
            effectId:=msoAnimEffectAppear)
        With effMovie.EffectInformation.PlaySettings
            .LoopUntilStopped = msoTrue
            .RewindMovie = msoTrue
        End With
    End With
End With

Issues Concerning Specifying Play Settings for a Media File

There are additional custom behaviors you can set for media files; however, setting these behaviors programmatically may have unexpected and undesirable results on other animation effects on your slide. In order to explain this, we need to spend a moment discussing how you use the PowerPoint object model to create animation effects:

There are two sections of the object model you can use to specify animation effects. You should use the new, expanded section, consisting of the TimeLine object and its children, for PowerPoint 2002 and later programming whenever possible. Use the original section, consisting of the AnimationSettings object and its child objects, only for programming PowerPoint 2000 and earlier versions. The AnimationSettings object model only supports entry effects. If you use the AnimationSettings object to set any effect properties, PowerPoint deletes any animation effects, other than entry effects, for the entire slide. Both the AnimationSettings and TimeLine object models directly access the PlaySettings object. However, because of a flaw in the object model, if you access certain PlaySettings properties, PowerPoint assumes you are doing so through the AnimationSettings object, and erases any non-entry effects for the entire slide. Accessing the following properties trigger this undesired behavior:

  • ActionVerb
  • HideWhileNotPlaying
  • PauseAnimation
  • PlayOnEntry
  • StopAfterSlides

PowerPoint does this only at the time at which you access the PlaySettings properties. So, if you set PlaySettings properties for media effects, you should do so before you add any other effects to a slide. Once you finish accessing the PlaySettings object for any media effects, you can add other effects and PowerPoint does not delete them.

Because this is a flaw in the object model, you can specify these settings through the PowerPoint user interface without adverse effects on other animation effects.

The following example inserts an .avi file as a media object, and then sets several of its custom behaviors, using the AnimationsSettings object model section. Again, you only use this approach if you are programming for PowerPoint 2000 and earlier versions.

Dim shpMovie As Shape

    With ActivePresentation.Slides(3).Shapes
        Set shpMovie = .AddMediaObject(FileName:="C:movie.avi", _
            Left:=100, _
            Top:=100)
        With shpMovie.AnimationSettings
            .Animate = msoTrue
            With .PlaySettings
                .HideWhileNotPlaying = msoTrue
                .PlayOnEntry = msoTrue
                .LoopUntilStopped = msoTrue
            End With
        End With
    End With

Linking and Embedding Media Files

PowerPoint determines whether media files are linked or embedded in the presentation. Video files, such as .avi, .mpg, or .asf files, are automatically linked; you cannot embed video files. Similarly, all audio files, other than .wav files, are automatically linked in the presentation. You can determine whether .wav files are linked or embedded in a presentation according to the size of the file. When you set the size limit for .wav files, PowerPoint automatically embeds any .wav files below the size you specify. To set the size limit, on the Tools menu click Options, and on the General tab, type the size limit (in kilobytes) in the Link sounds with file size greater than field. This is an application-level setting. This size limit option is not exposed as part of the PowerPoint object model, and so cannot be set programmatically.

PowerPoint calls a Microsoft Windows® API function, sndPlaySound, to play embedded .wav files. For other sounds, it uses either MCI or Microsoft Windows Media Player.

The figure below diagrams the factors that determine whether a media file is linked or embedded:

Figure 1. Determining whether a media file is linked or embedded

For linked objects, including linked media files, PowerPoint stores the linked file path as an absolute, rather than relative, file path. You cannot specify relative paths for linked files. However, if PowerPoint does not find the linked file in the expected path location, it looks in the same folder as the presentation to find the linked file. Placing all linked files in the same folder as the presentation that uses them should ensure that PowerPoint can find the files when needed.

Shapes representing linked objects contain a child object, the LinkFormat object, that contains properties and methods that enable you to get and set the linked file path, as well as options for update the linked object. For shapes that are not linked, including embedded files, the Shape.LinkFormat property returns an error.

There is no Shape object property that returns whether a file is linked or embedded. However, you can easily write code that tests whether a shape represents a linked file using the LinkFormat object. The following function determines if the specified Shape represents an embedded audio file. If the specified shape is a sound, the function attempts to access the LinkFormat.SourceFullName property; linked sounds return the full path of the linked file, while embedded sound files return an error.

Function IsEmbeddedSound(oShp As Shape) As Boolean
     On Error GoTo IsEmbed
     If Not (oShp.Type = msoMedia) Then
          IsEmbeddedSound = False
          Exit Function
     End If
     If Not (oShp.MediaType = ppMediaTypeSound) Then
          IsEmbeddedSound = False
          Exit Function
     End If
     'This line will throw an error if the file is embedded,
     'and work fine if it's linked.
     IsEmbeddedSound = ("" = oShp.LinkFormat.SourceFullName)
     Exit Function
IsEmbed: 'This line will catch the error and return TRUE,
               'as it must be an embedded sound.
IsEmbeddedSound = True
End Function

Inserting Media Files as OLE Objects

In the second method of adding a media file to a presentation, rather than inserting the file so that PowerPoint recognizes it as a media file, you insert the file as an Object Linking and Embedding (OLE) object. This approach presents significant disadvantages when compared with adding files as media objects:

  • You must install the OLE control for the OLE object on every computer on which you want to run the presentation.
  • Dealing with OLE objects requires more overhead and processing than working with media objects directly in PowerPoint.
  • When using OLE objects, you lose certain options available to you for objects that PowerPoint recognizes as media files.
  • Adding OLE objects to a PowerPoint presentation tends to significantly increase the size of the presentation file, even if the OLE objects are linked rather than embedded.

Because of these drawbacks, we recommend you add sound and video files to your presentations as media objects. About the only scenario were you would need to insert an OLE object rather than a media file would be if the media file was in a format that neither MCI nor Windows Media Player supported. Even then, the best approach would most likely be to convert the file into a more common, supported format, and then add the file as a media object.

Use the AddOLEObject method of a slide's Shapes collection to add an OLE object to a slide. Use the optional parameters of the method to specify the properties of the OLE object, including:

  • Position and size.
  • Whether to create the OLE object from an existing file, or create a new OLE object of the specified class type.
  • Whether to display the OLE object as an icon, with or without a label.
  • Whether to link or embed the OLE object. New OLE objects created from a class type must be embedded.

To set these, in the PowerPoint user interface, on the Insert menu, and then click Object.

The AddOLEObject method returns a Shape of type msoEmbeddedOLEobject or msoLinkedOLEObject. For example, the following function inserts a linked OLE object created from an existing file, and sets the object to display as an icon with a label.

Function InsertVideoAsOLEIcon(oleFile As String, _
    SlideNumber As Integer, IconLabel As String)
    With ActivePresentation.Slides(SlideNumber).Shapes
        .AddOLEObject Left:=120, Top:=110, _
            Width:=480, Height:=320, _
            FileName:=oleFile, _
            Link:=msoTrue, _
            DisplayAsIcon:=msoTrue, _
            IconFileName:="mplay32.exe", IconIndex:=1, _
            IconLabel:=IconLabel
    End With
End Function

Once you add the media file to your presentation as an OLE object, PowerPoint treats it as any other OLE object; PowerPoint does not recognize it as a media object. The actions the media file can perform are limited to the verbs that particular OLE class exposes. For example, media files inserted as Microsoft Media Player OLE objects expose the following three verbs: play, edit, and open.

Each Shape that represents an OLE object contains a OLEFormat object. The actions an OLE object can perform are contained in the ObjectVerbs collection, which is a child of the OLEFormat object. For example, the following code returns the verbs available for the specified OLE object:

Dim intCount As Integer

With ActivePresentation.Slides(5).Shapes("AVI File") _
    .OLEFormat.ObjectVerbs
    For intCount = 1 To .Count
        Debug.Print intCount & "  " & .Item(intCount)
    Next
End With

To request that an OLE object perform one of its actions, use the DoVerb method.

To specify that the OLE object perform one of its actions when the user clicks or moves the mouse over it during a presentation, set the Action property of the ActionSettings object to ppActionOLEVerb, and the ActionVerb property to the action you want the object to perform. For example, the following code sets the selected OLE object to play when the user moves the mouse over it during a presentation. This example assumes that the OLE object exposes a verb named "Play".

With ActivePresentation.Slides(5).Shapes("AVI File") _
    .ActionSettings.Item(ppMouseOver)
    .Action = ppActionOLEVerb
    .ActionVerb = "Play"
End With

Similarly, to specify that the OLE object perform one of its actions as part of a slide's animation sequence, set the ActionVerb property of the PlaySettings object to the verb you want the OLE object to perform. However, be aware that the other properties of the PlaySettings object are not accessible for OLE objects, because PowerPoint does not recognize them as media files. Therefore, you cannot take advantage of the custom behavior offered by the following properties:

  • HideWhileNotPlaying
  • LoopUntilStopped
  • PauseAnimation
  • PlayOnEntry
  • RewindMovie
  • StopAfterSlides

In addition, as with linked media files, the LinkFormat object contains methods and properties that apply to linked OLE objects, such as the linked file name and update options.

The figure below illustrations the OLEFormat object as it appears in the PowerPoint object model.

Figure 2. The OLEFormat Object in the PowerPoint Object Model

Conclusion

Beyond inserting your media files as media objects, there are several other things you can do to ensure the media in your presentations perform as expected:

  • Install the latest versions of Windows Media Player and Microsoft DirectX® on all computers on which you plan to run your presentations.
  • Update the video and sound card drivers on all computers on which you plan to run your presentations, as necessary.
  • Ensure that the computers on which you plan to run your presentations have the codecs necessary to decode and play the media files included in your presentation. If not, install the necessary codecs or re-encode your media files using codecs that are installed on the computers. (If you open the media file in Windows Media Player, Windows Media Player attempts to download and install the necessary codec(s) for you automatically.)

For more information about how PowerPoint uses the Media Control Interface, Windows Media Player and DirectX technology to play media files in a presentation, see How PowerPoint 2003 Plays Multimedia Files in a Presentation.