GemBox.Presentation is a .NET component that enables you to read, write, edit, convert, and print presentation files from your .NET applications using one simple API.

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
PowerPoint Library for C# / VB.NET Screenshot

See the full code below, use Run Example to execute.

using System;
using System.IO;
using System.Linq;
using GemBox.Presentation;
using GemBox.Presentation.Media;

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

        PresentationDocument presentation = new PresentationDocument();

        string pathToResources = "Resources";

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

        // Create and add audio content.
        AudioContent audio = null;
        using (var stream = File.OpenRead(Path.Combine(pathToResources, "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.
        Picture 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(Path.Combine(pathToResources, "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 Samples

    Sub Main()

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

        Dim presentation As PresentationDocument = New PresentationDocument

        Dim pathToResources As String = "Resources"

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

        ' Create and add audio content.
        Dim audio As AudioContent = Nothing
        Using stream As Stream = File.OpenRead(Path.Combine(pathToResources, "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 As Picture = audio.Picture

        ' Set drawing properties.
        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(Path.Combine(pathToResources, "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.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 sample.