So I’m writing a pptx parser and using OpenXML to get the data loaded in. It’s all going pretty well (that’s a lie – I’m actually ready to throw the computer across the room and jump out of the window), but I’ve run into an issue with loading videos that I simply can’t figure out. The problem is that OpenXML doesn’t seem to be able to locate the relationship tag that specifies video URIs.
What I’ve done is written code to cycle through the parts in the slide and log out their Ids, like so:
SlidePart slidePart = ...;
foreach(var curPart in slidePart.Parts)
Console.WriteLine("Part ID: " + curPart.RelationshipId);
So that works great – it logs out all of the relationships specified in the slide.xml.rels file – except for the video relationships for the relevant file. I can see the video relationship in the rels file, and it matches the link ID of the videoFile tag in the slide, but I can’t figure out how to get at it through code. I’ve got image loading working fine (OpenXML can find the image relationships). Are video relationships treated differently than other relationships? How can I get at the video URIs?
Video releationships are stored in the ExternalReleationships collection of a SlidePart.
Powerpoint embeds a video (external file) into a presentation in the following way (simplified):
Video) tag within a p:timing (classTiming) tag forthe slide containing the video.
The p:video tag contains a child called p:cMediaNode (class
CommonMediaNode).The p:cMediaNode contains a child called p:tgtEl (class
TargetElement).Again, the p:cMediaNode contains a child called p:spTgt (class
ShapeTarget) whichpoints to the ID of the picture shape releated to the video. The ID of the picture
shape is stored in the
NonVisualDrawingPropertiesIdmember.So, the video is connected to the picture shape via these Ids.
Furthermore, the picture shape contains a child called a:videoFile (class
VideoFromFile).The class VideoFromFile has a member called
Linkwhich points to the Id ofthe external releationship.
I highy recommend you to download the OpenXML SDK 2.0 productivity tool. This tool
allows you to inspect the generated XML of your presentation file.
The following code enumerates all videos for all slides in a given presentation.
For each video the Uri to the external file is printed. This is done by finding
the releated external releationship for the given video.
Of course, you could also directly enumerate the a:videoFile (class
VideoFromFile) tags.See the code below.