views:

51

answers:

1

I am working on a VSTO PowerPoint add-in which involves recording and playing sounds. I was requested at the last minute to allow users to pick the device that will play the sound, like Skype does.

In general, I don't think it is possible to specify what device PowerPoint should use, except by selecting the default device in the control panel, which I can't do programmatically. However I can recognize the sounds my add-in recorded because they are embedded as SoundEffect in Shapes that I tag.

My question is: is it possible to access the .wav file directly - something like the equivalent of SoundEffect.ImportFromFile, but in the other direction? If I could do that, I could open and play the .wav file using the add-in code, and not PowerPoint.

[Edit: by directly, I mean "without having to save the presentation under a different format"]

Alternatively, is there a way to add and retrieve binary files as embedded content in a presentation?

I suspect this is not possible, but that if someone knew, I would find that person on StackOverflow!

+4  A: 

Both are possible.

  1. Extract WAVs from PPTX: All embedded media are in the .pptx\ppt\media folder (rename .pptx to .zip, unzip and nav to \ppt\media). They are usually sequentially numbered in the order they were added and/or processed. Narration, AFAIK, is always embedded and never linked. The problem will be identifying the exact one to extract - that may be taken care by adding a tag or other unique identifier to it when adding to the pptx. The way to extract it is to use the Open XML SDK (or just System.IO.Packaging directly) and open an in-memory copy of the current presentation, locate your .wav in the folder (I use Linq-to-XML to find what I need) and read that into a memory stream for either writing to disk to play or if your add-in can play from a memory stream, even better.

  2. Binary types in PPTX: Anything can go into an Open XML document, but it's making it stay there that is the key. See this answer for details - http://stackoverflow.com/questions/3094519/is-it-possible-to-add-some-data-to-a-word-document/3128463#3128463.

Otaku
Thanks for the thorough answer Otaku. I should have specified in my question that saving under a different format wasn't an option in my case (it would be too slow and intrusive). I take it from your answer that IF I can save under a specific format, there are options, but that if I don't, I am out of luck. Is that correct?
Mathias
Do you mean 97-2003 format versus 2007/2010 format of PowerPoint? If so, what is listed above is for 2007/2010 only. It *may* be possible to do something with the earlier, I haven't tried. But the binary PowerPoint format specification is at: http://msdn.microsoft.com/en-us/library/cc313106(office.12).aspx.
Otaku
My bad, I hadn't fully understood your point - I thought your approach required first saving the file with a different extension. I have tried System.IO.Packaging, and it does opens a pptx file directly, and provides access to the various parts. Your caveat about pre-2007 files is a good one, though.
Mathias