Video separators are stored in the ExternalReleationships collection at SlidePart.
Powerpoint embeds the video (external file) in the presentation as follows (simplified):
- It creates the p: video (class
Video ) tag in the p: timing (class Timing ) tag for the slide containing the video. The p: video tag contains a child of p: cMediaNode (the CommonMediaNode class).
p: cMediaNode contains a child of p: tgtEl (class TargetElement ).
Again, p: cMediaNode contains a child p: spTgt (class ShapeTarget ) that points to the identifier of the shape of the image released on the video. The image identifier form is stored in the NonVisualDrawingProperties Id element. Thus, the video is associated with the image form through these identifiers.
In addition, the image form contains a child element called: videoFile (class VideoFromFile ). The VideoFromFile class has a member named Link that points to an external free identifier.
I recommend that you download the OpenXML SDK 2.0 productivity tool. This tool allows you to validate the generated XML of your presentation file.
The following code lists all the videos for all the slides in this presentation. For each video, Uri is printed to an external file. This is done by finding the issued external exemption for a given video.
using (var doc = PresentationDocument.Open("c:\\temp\\presentation.pptx", false)) { var presentation = doc.PresentationPart.Presentation; foreach (SlideId slideId in presentation.SlideIdList) { SlidePart slidePart = doc.PresentationPart.GetPartById(slideId.RelationshipId) as SlidePart; if (slidePart == null || slidePart.Slide == null) { continue; } Slide slide = slidePart.Slide; var videos = slide.Descendants<Video>(); Console.Out.WriteLine("Found videos for slide ID: {0}", slideId.Id); foreach (Video video in videos) { ShapeTarget shapeTarget = video.Descendants<ShapeTarget>().FirstOrDefault(); Console.Out.WriteLine("ShapeTargetId = {0}", shapeTarget.ShapeId); var videoFromFile = slide.CommonSlideData.ShapeTree.Descendants<Picture>(). Where<Picture>(p => p.NonVisualPictureProperties.Descendants<NonVisualDrawingProperties>().FirstOrDefault().Id == shapeTarget.ShapeId). FirstOrDefault().Descendants<VideoFromFile>().FirstOrDefault(); Console.Out.WriteLine("Releationship ID: {0}", videoFromFile.Link); var externalReleationship = slidePart.ExternalRelationships.Where(er => er.Id == videoFromFile.Link).FirstOrDefault(); if(externalReleationship == null)
Of course, you can also directly list a: videoFile tags (class VideoFromFile ). See code below.
foreach (SlideId slideId in presentation.SlideIdList) { SlidePart slidePart = doc.PresentationPart.GetPartById(slideId.RelationshipId) as SlidePart; if (slidePart == null || slidePart.Slide == null) { continue; } Slide slide = slidePart.Slide; var videos = slide.CommonSlideData.ShapeTree.Descendants<VideoFromFile>(); foreach (VideoFromFile video in videos) { Console.Out.WriteLine("Releationship ID: {0}", video.Link); var externalReleationship = slidePart.ExternalRelationships.Where(er => er.Id == video.Link).FirstOrDefault(); if(externalReleationship == null) { ReferenceRelationship rr = slidePart.GetReferenceRelationship(videoFromFile.Link); if (rr != null) { Console.Out.WriteLine(rr.Uri.OriginalString); } } else { Console.Out.WriteLine("Path to video file: {0}", externalReleationship.Uri.AbsolutePath); } } }
source share