Learn how to insert or extract audio in PowerPoint using Java: https://blog.aspose.com/2021/08/21/insert-or-extract-audio-in-powerpoint-using-java/
Last active
September 21, 2021 15:43
-
-
Save aspose-com-gists/c09e6c303ca65a21602154c569acc0a5 to your computer and use it in GitHub Desktop.
Insert and Extract Audio in PowerPoint using Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load presentation | |
Presentation pres = new Presentation("AudioSlide.pptx"); | |
try { | |
// Access the desired slide | |
ISlide slide = pres.getSlides().get_Item(0); | |
// Get the slideshow transition effects for slide | |
ISlideShowTransition transition = slide.getSlideShowTransition(); | |
// Extract sound in byte array | |
byte[] audio = transition.getSound().getBinaryData(); | |
System.out.println("Length: " + audio.length); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load or create presentation | |
Presentation pres = new Presentation("AudioFrameEmbed_out.pptx"); | |
try { | |
// Get the first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Load the wav sound file to stream | |
FileInputStream fstr = new FileInputStream(new File("audio.wav")); | |
// Add audio frame | |
IAudioFrame audioFrame = sld.getShapes().addAudioFrameEmbedded(50, 150, 100, 100, fstr); | |
fstr.close(); | |
// Change play mode to play on click | |
audioFrame.setPlayMode(AudioPlayModePreset.OnClick); | |
// Set volume to Low | |
audioFrame.setVolume(AudioVolumeMode.Low); | |
// Set audio to play across slides | |
audioFrame.setPlayAcrossSlides(true); | |
// Set audio to not loop | |
audioFrame.setPlayLoopMode(false); | |
// Hide AudioFrame during the slide show | |
audioFrame.setHideAtShowing(true); | |
// Rewind audio to start after playing | |
audioFrame.setRewindAudio(true); | |
// Save the PPTX file to disk | |
pres.save("AudioFrameEmbed_changed.pptx", SaveFormat.Pptx); | |
} finally { | |
if (pres != null) pres.dispose(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment