Video frames are used in PowerPoint presentations to demonstrate something or to attract the audience. Often, the videos are used to save time and make the presentations more effective. In this article, you will learn how to work with videos in presentations programmatically. Particularly, the article will cover how to embed or extract a video in a PowerPoint presentation using C#.
- .NET API to Embed Video in PowerPoint Presentations
- Embed a Video in a PowerPoint Presentation using C#
- Embed Video from Web Source
- Extract Video from a PowerPoint Presentation
.NET API to Embed Video in PowerPoint Presentations
In order to embed or extract videos in PowerPoint presentations, we will use Aspose.Slides for .NET. The API is designed to create and manipulate PowerPoint and OpenOffice documents. You can either install the API via NuGet or download its DLL.
PM> Install-Package Aspose.Slides.NET
Embed a Video in PowerPoint Presentation using C#
The following are the steps to embed a video in a PowerPoint presentation using C#.
- First, load the PowerPoint file or create a new one using Presentation class.
- Then, get reference of the desired slide in an ISlide object.
- Add a new video into the videos collection of the presentation using Presentation.Videos.AddVideo() method and get its reference into an IVideo object.
- Add a new video frame in the slide using ISlide.Shapes.AddVideoFrame(single, single, single, single, IVideo) method.
- Get reference of the video frame into an IVideoFrame object.
- Set the play mode and volume of the video.
- Finally, save presentation using Presentation.Save(String, SaveFormat) method.
The following code sample shows how to embed a video in a PowerPoint presentation using C#.
Embed Video in Presentations from a Web Source
You can also embed a video in the PowerPoint presentations from a web source. The following are the steps to achieve this.
- First, load the PowerPoint file or create a new one using Presentation class.
- Then, get reference of the desired slide in an ISlide object.
- Add a new video frame in the slide by specifying the video’s URL in ISlide.Shapes.AddVideoFrame(single, single, single, single, String) method.
- Get reference of the video frame into an IVideoFrame object.
- Set the play mode and volume of the video.
- Set thumbnail of the video using a WebClient.
- Save presentation using Presentation.Save(String, SaveFormat) method.
The following code sample shows how to embed a video into the presentation from a web source.
Extract Video from a PowerPoint Presentation in C#
Aspose.Slides for .NET also allows you to extract a video from a presentation. Below are the simple steps to achieve this.
- First, load the PowerPoint file using Presentation class.
- Then, loop through each ISlide in Presentation.Slides collection.
- For each ISlide object, loop through the collection of IShape in it.
- If IShape is a VideoFrame, then extract and save the embedded video.
The following code sample shows how to extract videos from a PowerPoint presentation using C#.
Get a Free API License
You can use Aspose.Slides for .NET without evaluation limitations by requesting a temporary license.
Conclusion
In this article, you have learned how to embed videos in PowerPoint presentations using C#. Moreover, you have seen how to extract videos from a presentation programmatically. In addition to this, you can visit the documentation to explore more about Aspose.Slides for .NET. Also, you can post your queries to our forum.