How to Set the Play Mode for Video in PowerPoint using C#, VB.NET

Video is often used to create a more attractive and interesting effect in PowerPoint, there are two modes to play video in PowerPoint: on click and automatically. In general, the video would be played by clicking on it, people who want to play the video automatically needs to set the default play mode as auto style. This article will demonstrate how to set the play mode for video in PowerPoint using C#, VB.NET.

Note: Before start, please download and install Spire.Presentation correctly, after that add the Spire.Presentation.dll file as the reference of your project.

Detail steps overview:

Step 1: Initialize a new presentation instance and load the original document from file.

Presentation presentation = new Presentation();
presentation.LoadFromFile(@"C:\Users\Administrator\Desktop\Sample.pptx");

Step 2: Find the video by looping through all the slides and set its play mode as auto.

foreach (ISlide slide in presentation.Slides)
{
    foreach (IShape shape in slide.Shapes)
        {
            if (shape is IVideo)
            {
                (shape as IVideo).PlayMode = VideoPlayMode.Auto;
            }
        }
}

Step 3: Save the file as Video.pptx.

presentation.SaveToFile("Video.pptx", FileFormat.Pptx2010);

Full codes:

[C#]
using Spire.Presentation;

namespace Set_Video_Play_Mode
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();
            presentation.LoadFromFile(@"C:\Users\Administrator\Desktop\Sample.pptx");
            foreach (ISlide slide in presentation.Slides)
            {
                foreach (IShape shape in slide.Shapes)
                {
                    if (shape is IVideo)
                    {
                        (shape as IVideo).PlayMode = VideoPlayMode.Auto;
                    }
                }
            }
            presentation.SaveToFile("Video.pptx", FileFormat.Pptx2010);
        }
    }
}
[VB.NET]
Imports Spire.Presentation
Namespace Set_Video_Play_Mode
	Class Program
		Private Shared Sub Main(args As String())
			Dim presentation As New Presentation()
	presentation.LoadFromFile("C:\Users\Administrator\Desktop\Sample.pptx")
			For Each slide As ISlide In presentation.Slides
				For Each shape As IShape In slide.Shapes
					If TypeOf shape Is IVideo Then
						TryCast(shape, IVideo).PlayMode = VideoPlayMode.Auto
					End If
				Next
			Next
			presentation.SaveToFile("Video.pptx", FileFormat.Pptx2010)
		End Sub
	End Class
End Namespace

If you couldn't use Spire.Presentation successfully, please refer the Spire.Presentation Quick Start which will guide you to quickly use the Spire.Presentation.