Audio can be used in PowerPoint document to create a more interesting and dynamic PowerPoint effect. Using the Spire.presention you can now use the Shapes.AppendVideoMedia() method to insert audio in your PowerPoint document at specific position with C#, VB.NET. There is guide will introduce the method.
Here are the steps:
Step 1: Create a new PowerPoint document first.
Presentation presentation = new Presentation();
Step 2: Then set the backgroung image before inserting Audio file.
string ImageFile = "2.jpg"; RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height); presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect); presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;
Step 3: Load the Audio file from disk and set properties of AutoShape
presentation.Slides[0].Shapes.AppendAudioMedia(@"1.mp3",500,100,true); IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(500, 100, 100, 150)); shape.ShapeStyle.LineColor.Color = Color.White; shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;
Step 4: Save the PowerPoint file and review.
presentation.SaveToFile("audio.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("audio.pptx");
Effect Screenshot:

Full code:
[C#]
using Spire.Presentation;
using System.Drawing;
namespace InsertAudio
{
class Program
{
static void Main(string[] args)
{
Presentation presentation = new Presentation();
string ImageFile = "2.jpg";
RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);
presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;
presentation.Slides[0].Shapes.AppendAudioMedia(@"1.mp3", 500, 100, true);
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(500, 100, 100, 150));
shape.ShapeStyle.LineColor.Color = Color.White;
shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;
presentation.SaveToFile("audio.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("audio.pptx");
}
}
}
[VB.NET]
Imports Spire.Presentation
Imports System.Drawing
Namespace InsertAudio
Class Program
Private Shared Sub Main(args As String())
Dim presentation As New Presentation()
Dim ImageFile As String = "2.jpg"
Dim rect As New RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height)
presentation.Slides(0).Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect)
presentation.Slides(0).Shapes(0).Line.FillFormat.SolidFillColor.Color = Color.FloralWhite
presentation.Slides(0).Shapes.AppendAudioMedia("1.mp3", 500, 100, True)
Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(500, 100, 100, 150))
shape.ShapeStyle.LineColor.Color = Color.White
shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None
presentation.SaveToFile("audio.pptx", FileFormat.Pptx2010)
System.Diagnostics.Process.Start("audio.pptx")
End Sub
End Class
End Namespace
