Audio and Video

Presentations may contain audio or video that can be played when a slideshow is running.

In the GemBox.Presentation API, the media-related types are grouped in the GemBox.Presentation.Media namespace.

The following example shows how to create and customize audio and video content using the GemBox.Presentation API.

Note: The playing of media created with the GemBox.Presentation API currently works only on MS PowerPoint 2013. In subsequent updates, we will add media-playing support for older versions of MS PowerPoint.

Screenshot of PowerPoint audio and video created with GemBox.Presentation
PowerPoint audio and video created with GemBox.Presentation
using System.IO;
using GemBox.Presentation;
using GemBox.Presentation.Media;

class Program
{
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        var presentation = new PresentationDocument();

        // Create new presentation slide.
        var slide = presentation.Slides.AddNew(SlideLayoutType.Custom);

        // Create and add audio content.
        AudioContent audio = null;
        using (var stream = File.OpenRead("%#Applause.wav%"))
            audio = slide.Content.AddAudio(AudioContentType.Wav, stream, 2, 2, LengthUnit.Centimeter);

        // Set the ending fade durations for the media.
        audio.Fade.End = TimeOffset.From(300, TimeOffsetUnit.Millisecond);

        // Get the picture associated with this media.
        var picture = audio.Picture;

        // Set drawing properties.
        picture.Action.Click.Set(ActionType.PlayMedia);
        picture.Layout.Width = Length.From(7, LengthUnit.Centimeter);
        picture.Layout.Height = Length.From(7, LengthUnit.Centimeter);
        picture.Name = "Applause.wav";

        // Create and add video content.
        VideoContent video = null;
        using (var stream = File.OpenRead("%#Wildlife.wmv%"))
            video = slide.Content.AddVideo("video/x-ms-wmv", stream, 10, 2, 10, 5.6, LengthUnit.Centimeter);

        // Set drawing properties.
        video.Picture.Action.Click.Set(ActionType.PlayMedia);
        video.Picture.Name = "Wildlife.wmv";

        // Set the amount of time to be trimmed from the start and end of the media.
        video.Trim.Start = TimeOffset.From(600, TimeOffsetUnit.Millisecond);
        video.Trim.End = TimeOffset.From(800, TimeOffsetUnit.Millisecond);

        // Set the starting and ending fade durations for the media.
        video.Fade.Start = TimeOffset.From(100, TimeOffsetUnit.Millisecond);
        video.Fade.End = TimeOffset.From(200, TimeOffsetUnit.Millisecond);

        // Add video bookmarks.
        video.Bookmarks.Add(TimeOffset.From(1500, TimeOffsetUnit.Millisecond));
        video.Bookmarks.Add(TimeOffset.From(3000, TimeOffsetUnit.Millisecond));

        presentation.Save("Audio and Video.pptx");
    }
}
Imports System.IO
Imports GemBox.Presentation
Imports GemBox.Presentation.Media

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim presentation = New PresentationDocument

        ' Create New presentation slide.
        Dim slide = presentation.Slides.AddNew(SlideLayoutType.Custom)

        ' Create and add audio content.
        Dim audio As AudioContent = Nothing
        Using stream As Stream = File.OpenRead("%#Applause.wav%")
            audio = slide.Content.AddAudio(AudioContentType.Wav, stream, 2, 2, LengthUnit.Centimeter)
        End Using

        ' Set the ending fade durations for the media.
        audio.Fade.End = TimeOffset.From(300, TimeOffsetUnit.Millisecond)

        ' Get the picture associated with this media.
        Dim picture = audio.Picture

        ' Set drawing properties.
        picture.Action.Click.Set(ActionType.PlayMedia)
        picture.Layout.Width = Length.From(7, LengthUnit.Centimeter)
        picture.Layout.Height = Length.From(7, LengthUnit.Centimeter)
        picture.Name = "Applause.wav"

        ' Create and add video content.
        Dim video As VideoContent = Nothing
        Using stream As Stream = File.OpenRead("%#Wildlife.wmv%")
            video = slide.Content.AddVideo("video/x-ms-wmv", stream, 10, 2, 10, 5.6, LengthUnit.Centimeter)
        End Using

        ' Set drawing properties.
        video.Picture.Action.Click.Set(ActionType.PlayMedia)
        video.Picture.Name = "Wildlife.wmv"

        ' Set the amount of time to be trimmed from the start And end of the media.
        video.Trim.Start = TimeOffset.From(600, TimeOffsetUnit.Millisecond)
        video.Trim.End = TimeOffset.From(800, TimeOffsetUnit.Millisecond)

        ' Set the starting And ending fade durations for the media.
        video.Fade.Start = TimeOffset.From(100, TimeOffsetUnit.Millisecond)
        video.Fade.End = TimeOffset.From(200, TimeOffsetUnit.Millisecond)

        ' Add video bookmarks.
        video.Bookmarks.Add(TimeOffset.From(1500, TimeOffsetUnit.Millisecond))
        video.Bookmarks.Add(TimeOffset.From(3000, TimeOffsetUnit.Millisecond))

        presentation.Save("Audio and Video.pptx")
    End Sub
End Module

Check next example or download examples from GitHub.