You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: 'How to: Add an audio file to a slide in a presentation'
9
+
ms.suite: office
10
+
11
+
ms.author: o365devx
12
+
author: o365devx
13
+
ms.topic: conceptual
14
+
ms.date: 03/31/2025
15
+
ms.localizationpriority: medium
16
+
---
17
+
18
+
# Add an audio file to a slide in a presentation
19
+
20
+
This topic shows how to use the classes in the Open XML SDK for
21
+
Office to add an audio file to the last slide in a presentation
22
+
programmatically.
23
+
24
+
## Getting a Presentation Object
25
+
26
+
In the Open XML SDK, the <xref:DocumentFormat.OpenXml.Packaging.PresentationDocument> class represents a presentation document package. To work with a presentation document,
27
+
first create an instance of the `PresentationDocument` class, and then work with
28
+
that instance. To create the class instance from the document call the <xref:DocumentFormat.OpenXml.Packaging.PresentationDocument.Open*> method that uses a file path, and a
29
+
Boolean value as the second parameter to specify whether a document is editable. To open a document for read/write, specify the value `true` for this parameter as shown in the following
30
+
`using` statement. In this code, the file parameter is a string that represents the path for the file from which you want to open the document.
The PresentationML document consists of a number of parts, among which is the Picture (`<pic/>`) element.
46
+
47
+
The following text from the [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)] specification introduces the overall form of a `PresentationML` package.
48
+
49
+
Audio File (`<audioFile/>`) specifies the presence of an audio file. This element is specified within the non-visual properties of an object. The audio shall be attached to an object as this is how it is represented within the document. The actual playing of the audio however is done within the timing node list that is specified under the timing element.
50
+
51
+
Consider the following ``Picture`` object that has an audio file attached to it.
52
+
53
+
```xml
54
+
<p:pic>
55
+
<p:nvPicPr>
56
+
<p:cNvPrid="7"name="Rectangle 6">
57
+
<a:hlinkClickr:id=""action="ppaction://media"/>
58
+
</p:cNvPr>
59
+
<p:cNvPicPr>
60
+
<a:picLocksnoRot="1"/>
61
+
</p:cNvPicPr>
62
+
<p:nvPr>
63
+
<a:audioFiler:link="rId1"/>
64
+
</p:nvPr>
65
+
</p:nvPicPr>
66
+
</p:pic>
67
+
```
68
+
69
+
In the above example, we see that there is a single audioFile element attached to this picture. This picture is placed within the document just as a normal picture or shape would be. The id of this picture, namely 7 in this case, is used to refer to this audioFile element from within the timing node list. The Linked relationship id is used to retrieve the actual audio file for playback purposes.
The code first creates a media data part for the audio file to be added. With the audio file stream open, it feeds the media data part object. Next, audio and media relationship references are added to the slide using the provided embedId for future reference to the audio file and mediaEmbedId for media reference.
99
+
100
+
An image part is then added with a sample picture to be used as a placeholder for the audio. A picture object is created with various elements, such as Non-Visual Drawing Properties (`<cNvPr/>`), which specify non-visual canvas properties. This allows for additional information that does not affect the appearance of the picture to be stored. The `<audioFile/>` element, explained above, is also included. The HyperLinkOnClick (`<hlinkClick/>`) element specifies the on-click hyperlink information to be applied to a run of text or image. When the hyperlink text or image is clicked, the link is fetched. Non-Visual Picture Drawing Properties (`<cNvPicPr/>`) specify the non-visual properties for the picture canvas. For a detailed explanation of the elements used, please refer to [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)]
Next the Media(CT_Media) element is created with use of the previously referenced mediaEmbedId(Embedded Picture Reference). The Blip element is also added; this element specifies the existence of an image (binary large image or picture) and contains a reference to the image data. Blip's Embed attribute is used to specify an placeholder image in the Image Part created previously.
All other elements such as Offset(`<off/>`), Stretch(`<stretch/>`), fillRectangle(`<fillRect/>`), are appended to the ShapeProperties(`<spPr/>`) and ShapeProperties are appended to the Picture element(`<pic/>`). Finally the picture element that includes audio is added to the ShapeTree(`<sp/>`) of the slide.
119
+
120
+
Following is the complete sample code that you can use to add audio to the slide.
Copy file name to clipboardExpand all lines: docs/word/how-to-accept-all-revisions-in-a-word-processing-document.md
+81-3Lines changed: 81 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ Using the Open XML SDK, you can create document structure and content using stro
46
46
47
47
## ParagraphPropertiesChange Element
48
48
49
-
When you accept a revision mark, you change the properties of a paragraph either by deleting an existing text or inserting a new text. In the following sections, you read about three elements that are used in the code to change the paragraph contents, mainly, `<w: pPrChange>` (Revision Information for Paragraph Properties), `<w:del>` (Deleted Paragraph), and `<w:ins>` (Inserted Table Row) elements.
49
+
When you accept a revision mark, you change the properties of a paragraph either by deleting existing text or inserting new text. In the following sections, you read about three elements that are used in the code to change the paragraph contents, mainly, `<w: pPrChange>` (Revision Information for Paragraph Properties), `<w:del>` (Deleted Paragraph), and `<w:ins>` (Inserted Table Row) elements.
50
50
51
51
The following information from the [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)] specification introduces the `ParagraphPropertiesChange` element (`pPrChange`).
52
52
@@ -86,9 +86,12 @@ This element specifies that the paragraph mark delimiting the end of a paragraph
86
86
87
87
Consider a document consisting of two paragraphs (with each paragraph delimited by a pilcrow ¶):
88
88
89
-
 If the physical character delimiting the end of the first paragraph is deleted and this change is tracked as a revision, the following will result:
89
+

90
+
91
+
If the physical character delimiting the end of the first paragraph is deleted and this change is tracked as a revision, the following will result:
90
92
91
93

94
+
92
95
This revision is represented using the following WordprocessingML:
This element marks the end of a region where the move source contents are part of a single named move.
205
+
The following information from the [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)] specification
206
+
introduces the Move From Range End element (`moveFromRangeEnd`).
207
+
208
+
## The Moved To Element
209
+
The following information from the [!include[ISO/IEC 29500 URL](../includes/iso-iec-29500-link.md)] specification
210
+
introduces the MoveTo element (`moveTo`).
211
+
212
+
### moveTo (Move Destination Paragraph)
213
+
This element specifies that the parent paragraph has been moved to this location and tracked as a revision.
214
+
This does not imply anything about the revision state of the contents of the paragraph, and applies only to the existence of the paragraph as its own unique paragraph.
215
+
216
+
Consider a WordprocessingML document in which a paragraph of text is moved down in the document.
217
+
This moved paragraph would be represented using the following WordprocessingML markup:
0 commit comments