Video
Contents
[
Hide
]
This article demonstrates how to add video frames and set playback options using Aspose.Slides for Python via Java.
Install the package as described in Installation. Each example imports asposeslides before starting the JVM, then imports the API after the JVM is running.
Add a Video Frame
Insert a video frame that references an external video file.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
# Add a video frame linked to a video file.
video_frame = slide.getShapes().addVideoFrame(50, 50, 320, 240, "video.mp4")
finally:
presentation.dispose()
Access a Video Frame
Retrieve the first video frame added to a slide.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation, VideoFrame
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
slide.getShapes().addVideoFrame(50, 50, 320, 240, "video.mp4")
# Access the first video frame on the slide.
first_video = None
for shape in slide.getShapes():
if isinstance(shape, VideoFrame):
first_video = shape
break
if first_video is None:
print("The slide contains no video frames.")
finally:
presentation.dispose()
Remove a Video Frame
Delete a video frame from the slide.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
video_frame = slide.getShapes().addVideoFrame(50, 50, 320, 240, "video.mp4")
# Remove the video frame.
slide.getShapes().remove(video_frame)
finally:
presentation.dispose()
Set Video Playback
Configure the video to play automatically when the slide is displayed.
import jpype
import asposeslides
if not jpype.isJVMStarted():
jpype.startJVM()
from asposeslides.api import Presentation, VideoPlayModePreset
presentation = Presentation()
try:
slide = presentation.getSlides().get_Item(0)
video_frame = slide.getShapes().addVideoFrame(50, 50, 320, 240, "video.mp4")
# Configure the video to play automatically.
video_frame.setPlayMode(VideoPlayModePreset.Auto)
finally:
presentation.dispose()