Working with Embedded Media in PowerPoint 2010
Summary: Learn how to programmatically embed media files into a Microsoft PowerPoint 2010 presentation.
Applies to: Office 2010 | PowerPoint 2010 | Visual Studio
Published: October 2010
Provided by: Michael Case, iSoftStone
By using Microsoft PowerPoint 2010, you can effectively engage your audience by embedding and customizing videos within your presentation. This Visual How To shows how to use the PowerPoint 2010 Primary Interop Assembly (PIA) to programmatically create a new PowerPoint 2010 presentation, add a new slide to the presentation, embed a video into the new slide, and format how the video will be displayed. This Visual How To uses the following steps to show how to programmatically embed media files in a PowerPoint presentation:
Copying the Sample Video File to the C:\temp Directory The sample code presented with this Visual How To uses the Butterfly.wmv file that is usually located in the sample videos directory. The Butterfly.wmv file has to be copied to the C:\TEMP directory for the sample code to work without modification. If the Butterfly.wmv file is not available, you can use another video file. When you use another video file, you must modify the sample code's mediaFileName variable to include the full path and name of the video file to be embedded. PowerPoint 2010 allows the following video file formats to be embedded: Windows Media Video (.wmv), Windows Video (.avi), Windows Media (.asf), Movie (.mpg or .mpeg), and Adobe Flash Media (.flv). To copy the sample video file to the C:\TEMP directory
Creating a Windows Console Application in Visual Studio 2010 This Visual How To uses a Windows console application as the framework for the sample code. The console application type was selected only for its simplicity. Other application types could use the same approach presented here. To create a Windows console application in Visual Studio 2010
Adding References to the Required Assemblies This Visual How To uses the PowerPoint 2010 Primary Interop Assembly (PIA) to create and manipulate a PowerPoint presentation. The PowerPoint 2010 PIA exposes the PowerPoint 2010 object model to managed code and is installed with Visual Studio 2010. The PowerPoint 2010 PIA has a dependency to classes in the Microsoft.Office.Core namespace that requires a reference to the Office assembly to be added, also. To add a reference to the PowerPoint 2010 Primary Interop Assembly
To add a reference to the Office assembly
Adding the Sample Code to the Solution Replace the contents of the Program.cs source file with the following code. The code creates a PowerPoint 2010 presentation named PowerPoint2010EmbeddedVideo.pptx in the C:\TEMP folder. The code then adds a new slide to the presentation, embeds a video file in the slide, and then formats how the video will be displayed.
The following excerpt from the preceding code example shows how to use the PowerPoint 2010 PIA to embed a video into a slide and format how it will be displayed. The code embeds the video by using the AddMediaObject2 method. The FileName parameter is the name of the video file to embed. The LinkToFile parameter is set to false, and the SaveWithDocument parameter is set to true to embed the file within the presentation. The Left and Top parameters are used to define the location of the upper-left corner for the video display area. Named arguments are used because all of the parameters are not passed to the AddMediaObject2 method. For more information about named arguments, see Named and Optional Arguments. The video file is then reset to its original size by calling the ScaleHeight and ScaleWidth methods. The first parameter is the factor to use when resizing, and the second parameter defines that resizing should be based on the original size. The video file is then formatted to be displayed with a beveled edge by using the ThreeDBevelTopDepth, BevelTopInset, and BevelBottomType properties. The video file is also formatted to display in a rounded rectangle shape by setting the AutoShapeType property to the msoAutoShapeType.msoShapeRoundedRectangle value.
|
> [!VIDEO https://www.microsoft.com/en-us/videoplayer/embed/02e51c2e-388c-4b8c-9479-e506351b0e7c] Length: 04:38 |