Introduction
Developers can also add and play video files in the slides to enrich their presentations. Aspose.Slides supports adding Video Frames to the slides that make it possible for developers to add videos to their presentations. This topic will help developers to follow the simple steps with examples for adding video frames in their slides.
Adding Video Frames to Slides
To add a Video 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
- Add the Video Frame (containing the video file name) into the slide
- Write the modified presentation as a PPT file
In the example given below, we have added a Video 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(1);
//Adding the video frame into the slide
slide.Shapes.AddVideoFrame(1900,1100, 2000, 2000, "C:\\demo.avi");
//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(1)
'Adding the video frame into the slide
slide.Shapes.AddVideoFrame(1900,1100, 2000, 2000, "C:\\demo.avi")
'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(1);
//Adding the video frame into the slide
slide.getShapes().addVideoFrame(1900,1100, 2000, 2000, "C:\\demo.avi");
//Writing the presentation as a PPT file
pres.write(new FileOutputStream(new File("modified.ppt")));
}
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(1);
//Adding the video frame into the slide
$slide->getShapes()->addVideoFrame(1900,1100, 2000, 2000, "C:\\demo.avi");
//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();
}
catch(JavaException $ex)
{
echo $ex->toString();
}
?>
The above code snippet adds a Video Frame to the slide as shown below:
|
Figure: Video Frame added into the slide
|
Video Frame appears on the slide as a media player. To play this video file, you can right click on the shape and select Play Movie as shown below in the figure:
|
Figure: Playing video in the slide
|