どのようにオーディオファイルとビデオファイルを追加する


スライドが広告キャンペーンまたは製品デモンストレーションのために使われるとき、人々は通常プレゼンテーションをより鮮明でダイナミックにするためにメディアファイル(オーディオとビデオのような)を加えます.この記事では、あなたのPowerPointプレゼンテーションにオーディオとビデオファイルを挿入する方法を示します.Java用プレゼンテーション.

尖塔を加える。プレゼンテーション。依存関係のjar


方法1 :ダウンロードFree Spire.Presentation for Javaパックは、それを解凍し、あなたは尖塔を取得します.プレゼンテーション.「lib」フォルダからのJARファイル.プロジェクトのJARファイルを依存関係としてインポートします.
方法2 : Mavenプロジェクトを作成している場合は、POMに次の構成を追加することで、JAR依存を簡単に追加できます.XML
<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId> e-iceblue </groupId>
        <artifactId>spire.presentation.free</artifactId>
        <version>2.6.1</version>
    </dependency>
</dependencies>

例1スライドにオーディオを追加


import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import java.awt.*;
import java.awt.geom.Rectangle2D;

public class InsertAudio {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();


        //Load a sample PowerPoint document
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\example.pptx");

        //Add a shape to the first slide
        Rectangle2D.Double labelRect= new Rectangle2D.Double(50, 120, 120, 30);
        IAutoShape labelShape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, labelRect);
        labelShape.getLine().setFillType(FillFormatType.NONE);
        labelShape.getFill().setFillType(FillFormatType.NONE);
        labelShape.getTextFrame().setText("Double Click to Play Audio:");
        labelShape.getTextFrame().getTextRange().setFontHeight(20);
        labelShape.getTextFrame().getTextRange().setLatinFont(new TextFont("Times New Roman"));
        labelShape.getTextFrame().getTextRange().getFill().setFillType(FillFormatType.SOLID);
        labelShape.getTextFrame().getTextRange().getFill().getSolidColor().setColor(Color.BLACK);

        //Add an audio file to the slide
        Rectangle2D.Double audioRect = new Rectangle2D.Double(175, 120, 30, 30);
        IAudio audio = presentation.getSlides().get(0).getShapes().appendAudioMedia((new java.io.File("C:\\Users\\Administrator\\Desktop\\music.wav")).getAbsolutePath(), audioRect);
        audio.setPlayMode(AudioPlayMode.ON_CLICK);

        //Save to file
        presentation.saveToFile("AddAudio.pptx", FileFormat.PPTX_2013);
        presentation.dispose();
    }
}
出力

例2ビデオをスライドに追加


import com.spire.presentation.*;
import com.spire.presentation.drawing.FillFormatType;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;

public class InsertVideo {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Load a sample PowerPoint file
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\example.pptx");

        //Add a shape to the first slide
        Rectangle2D.Double labelRect = new Rectangle2D.Double(50, 120, 120, 50);
        IAutoShape labelShape = presentation.getSlides().get(0).getShapes().appendShape(ShapeType.RECTANGLE, labelRect);
        labelShape.getLine().setFillType(FillFormatType.NONE);
        labelShape.getFill().setFillType(FillFormatType.NONE);
        labelShape.getTextFrame().setText("Play Video:");
        labelShape.getTextFrame().getTextRange().setFontHeight(20);
        labelShape.getTextFrame().getTextRange().setLatinFont(new TextFont("Times New Roman"));
        labelShape.getTextFrame().getTextRange().getFill().setFillType(FillFormatType.SOLID);
        labelShape.getTextFrame().getTextRange().getFill().getSolidColor().setColor(Color.BLACK);

        //Append a video file to the slide and set the cover image
        Rectangle2D.Double videoRect = new Rectangle2D.Double(175, 120, 400, 225);
        IVideo video = presentation.getSlides().get(0).getShapes().appendVideoMedia((new java.io.File("C:\\Users\\Administrator\\Desktop\\video.mp4")).getAbsolutePath(), videoRect);
        BufferedImage coverImage = ImageIO.read( new File("C:\\Users\\Administrator\\Desktop\\coverImage.jpg"));
        video.getPictureFill().getPicture().setEmbedImage(presentation.getImages().append(coverImage));

        //Save to file
        presentation.saveToFile("AddVideo.pptx", FileFormat.PPTX_2010);
        presentation.dispose();
    }
}
出力