This how-to topic focuses on how to add audio in Presentation using Java by providing the detailed steps to configure the environment and using the the application code. You can use this application in any of Java environments configured in Linux, Windows or macOS without any dependence on Microsoft PowerPoint or any third-party software to embed audio in PPTX using Java.
Steps to Insert Audio in Presentation using Java
- Configure the development environment to use Aspose.Slides for Java JAR file from repository manager to insert an audio frame inside the presentation
- Create a sample presentation using an instance of the Presentation class to insert an audio inside the presentation
- Access the desired slide inside the presentation slides collection to add an audio frame
- Load the audio file from the disk and insert that inside the presentation slide audio frame
- Load the image from the disk and set that as an audio frame image
- Save the presentation having an audio frame inside on the disk
By following the above steps in Java inserting audio in PowerPoint presentation can be easily managed using a few API calls whereby the process will commence by creating a default presentation using an instance of the Presentation class, which will then be followed by accessing the desired slide inside the presentation. Then an audio file and image will be loaded from the disk and set that inside the audio frame for the slide. Finally, a presentation having a slide with an embedded audio frame will be saved on the disk.
Code to Insert Audio in Presentation using Java
The aforementioned example covers how easily in Java saving MP3 audio in PPT presentation is made possible using a very simple API interface. We have used the IAudioFrame class that also let you set the additional flags for the features like rewind mode, play mode, play audio in a loop and hiding a audio to name a few. Once the audio will be embedded inside the presentation, you can save it on the disk or inside a memory stream as per your requirements.
This example focuses on, how to insert audio in Presentation using Java. If you are interested in learning about adding a video inside the presentation, refer to the article on How to Add Video in Presentation using Java.