本文将介绍如何使用spire.presentation for java组件在powerpoint文档中插入视频、提取视频以及设置视频的播放模式。
插入视频
import java.awt.rectangle;
import com.spire.presentation.fileformat;
import com.spire.presentation.islide;
import com.spire.presentation.presentation;
public class insertradio {
public static void main(string[] args) throws exception {
//实例化一个presentation对象
presentation ppt = new presentation();
ppt.loadfromfile("e:\\演示文稿.pptx");
//获取第一张幻灯片
islide slide = ppt.getslides().get(0);
//插入视频到第一张幻灯片
slide.getshapes().appendvideomedia("e:\\视频.mp4", new rectangle(300, 150, 300, 150));
//保存文件
ppt.savetofile("e:\\插入视频.pptx", fileformat.pptx_2010);
}
}
提取视频
import com.spire.presentation.ishape;
import com.spire.presentation.islide;
import com.spire.presentation.ivideo;
import com.spire.presentation.presentation;
public class exportvideo {
public static void main(string[] args) throws exception {
//实例化一个ppt对象并加载示例文档
presentation ppt = new presentation();
ppt.loadfromfile("e:\\插入视频.pptx");
//获取第一张幻灯片
islide slide = ppt.getslides().get(0);
ivideo video = null;
for(int i = 0; i< slide.getshapes().getcount(); i )
{
ishape shape = slide.getshapes().get(i);
if ((shape instanceof ivideo)) {
//保存视频
video = (ivideo) shape;
video.getembeddedvideodata().savetofile("e:\\视频\\提取视频" i ".mp4");
}
}
}
}
设置视频播放模式
import com.spire.presentation.fileformat;
import com.spire.presentation.ishape;
import com.spire.presentation.islide;
import com.spire.presentation.ivideo;
import com.spire.presentation.presentation;
import com.spire.presentation.videoplaymode;
public class playtype {
public static void main(string[] args) throws exception {
//实例化一个presentation对象并加载示例文档
presentation presentation = new presentation();
presentation.loadfromfile("e:\\插入视频.pptx");
//获取第一张幻灯片
islide slide = presentation.getslides().get(0);
ivideo video = null;
for(int i = 0; i< slide.getshapes().getcount(); i )
{
ishape shape = slide.getshapes().get(i);
if ((shape instanceof ivideo)) {
video = (ivideo) shape;
//设置视频的播放模式为自动播放
//video.setplaymode(videoplaymode.auto);
//设置视频的播放模式为单击时播放
video.setplaymode(videoplaymode.on_click);
}
}
//保存ppt文档
presentation.savetofile("e:\\单击播放.pptx", fileformat.pptx_2010);
}
}