PowerPoint presentations often contain video frames to demonstrate something or to attract the audience. In many cases, the videos are used to save time and make the presentations effective. In this article, you will learn how to work with videos in PowerPoint files programmatically. Particularly, the article will cover how to embed or extract a video in a PowerPoint presentation using Java.
- Java API to Embed Video in PowerPoint Presentations
- Embed a Video in a PowerPoint Presentation using Java
- Embed Video from Web Source
- Extract Video from a PowerPoint Presentation
Java API to Embed Video in PowerPoint Presentations
In order to embed or extract videos in PowerPoint presentations, we will use Aspose.Slides for Java. The API is designed to create and manipulate PowerPoint and OpenOffice documents. You can either download the API’s JAR or install it using the following Maven configurations.
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-slides</artifactId>
<version>21.8</version>
<classifier>jdk16</classifier>
</dependency>
Embed a Video in PowerPoint Presentation using Java
The following are the steps to embed a video in a PowerPoint presentation using Java.
- 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.getVideos().addVideo() method and get its reference into an IVideo object.
- Add a new video frame in the slide using ISlide.getShapes().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 Java.
Embed Video from a Web Source using Java
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.getShapes().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.
- Finally, 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 Java
Aspose.Slides for Java 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.getSlides() 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 Java.
Get a Free API License
You can use Aspose.Slides for Java without evaluation limitations by requesting a temporary license.
Conclusion
In this article, you have learned how to embed videos in PowerPoint presentations using Java. 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 Java. Also, you can post your queries to our forum.
See Also
- Add Watermark to PowerPoint Slides using Java
- Extract Text from PowerPoint Files using Java
- Add, Connect, Remove, or Clone PowerPoint Shapes in Java
- Convert PowerPoint PPTX/PPT to PNG Images in Java
- Generate Thumbnails for PowerPoint PPTX or PPT using Java
Info: Aspose recently developed a free MP4 to MP3 web app that can be used to extract audio from video files.