Introduction
Aspose.Slides allows developers to add audio files in their slides. These audio files are embedded in the slides as Audio Frames. An Audio Frame contains the embedded audio file. In this topic, we will discuss that how can developers embed audio frames in their slides using Aspose.Slides.
Adding Audio Frames to Slides
To add an Embedded Audio Frame in a slide using Aspose.Slides, please follow the steps below:
- Create an instance of Presentation class
- Obtain the reference of a slide by using its Position
- Open the Audio File Stream to be embedded in the slide
- Add the Embedded Audio Frame (containing audio file) into the slide
- Write the modified presentation as a PPT file
In the example given below, we have added an Embedded Audio Frame into the slide.
Example:
[C#]
//Instantiate a Presentation object that represents a PPT file
Presentation pres=new Presentation("demo.ppt");
//Accessing a slide using its slide position
Slide slide = pres.GetSlideByPosition(2);
//Opening the audio file as a stream
FileStream fstr = new FileStream("C:\\Chimes.wav", FileMode.Open, FileAccess.Read);
//Adding the embedded audio frame into the slide
slide.Shapes.AddAudioFrameEmbedded(2600, 1800, 500, 500, fstr);
//Writing the presentation as a PPT file
pres.Write("C:\\modified.ppt");
[VB.NET]
'Instantiate a Presentation object that represents a PPT file
Dim pres As Presentation = New Presentation("demo.ppt")
'Accessing a slide using its slide position
Dim slide As Slide = pres.GetSlideByPosition(2)
'Opening the audio file as a stream
Dim fstr As FileStream = New FileStream("C:\\Chimes.wav",FileMode.Open,FileAccess.Read)
'Adding the embedded audio frame into the slide
slide.Shapes.AddAudioFrameEmbedded(2600, 1800, 500, 500, fstr)
'Writing the presentation as a PPT file
pres.Write("C:\\modified.ppt")
[Java]
try
{
//Instantiate a Presentation object that represents a PPT file
Presentation pres = new Presentation(new FileInputStream(new File("demo.ppt")));
//Accessing a slide using its slide position
Slide slide = pres.getSlideByPosition(2);
//Opening the audio file as a stream
FileInputStream fstr = new FileInputStream(new File("C:\\Chimes.wav"));
//Adding the embedded audio frame into the slide
slide.getShapes().addAudioFrameEmbedded(2600, 1800, 500, 500, fstr);
//Writing the presentation as a PPT file
pres.write(new FileOutputStream(new File("modified.ppt")));
//Closing the stream
fstr.close();
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
[PHP]
<?php
//Using aspose.slides.jar file so that the classes inside the jar file
//can be used
java_require("aspose.slides.jar");
try
{
//Creating a file input stream to read the PPT file
$fistream=new Java("java.io.FileInputStream","C:\\demo.ppt");
//Instantiate a Presentation object that represents a PPT file
$pres=new Java("com.aspose.slides.Presentation",$fistream);
//Accessing a slide using its slide position
$slide=$pres->getSlideByPosition(2);
//Opening the audio file as a stream
$fstr=new Java("java.io.FileInputStream","C:\\Chimes.wav");
//Adding the embedded audio frame into the slide
$slide->getShapes()->addAudioFrameEmbedded(2600, 1800, 500, 500, $fstr);
//Creating a file output stream to write the output file
$fostream=new Java("java.io.FileOutputStream","C:\\modified.ppt");
//Writing the presentation as a PPT file
$pres->write($fostream);
//Closing the streams
$fistream->close();
$fostream->close();
$fstr->close();
}
catch(JavaException $ex)
{
echo $ex->toString();
}
?>
The above code snippet adds an Embedded Audio Frame to the slide as shown below:
|
Figure: Audio Frame embedded in the slide
|
Audio Frame appears on the slide as an icon of speaker. To play this audio file, you can right click on the shape and select Play Sound as shown below in the figure:
|
Figure: Playing embedded sound in the slide
|