Playing Sound Clips Without Seeing the Icon
So here it is, my first official blog entry dealing with programming PowerPoint presentations. It’s a modest tip, but then, I’m still learning my way around the PowerPoint object model.
When you insert a sound clip into a PowerPoint presentation, a small icon representing the sound file appears on the specified slide. Which is fine if you intend to start the sound file playing by user interaction, that is, by clicking on the icon or moving your mouse over top of it. But what if you just want the clip to play automatically when the slide loads? Then the icon is just visual clutter.
In the user interface, if you drag the icon off into the ‘work space’ area around the slide, then the icon won’t appear during the presentation. Just remember to set the sound clip to play automatically when the slide appears, however, because without the icon you don’t have any way to start the slide during the presentation itself.
The following code does the same thing programmatically. First, it inserts the sound file. Then it moves the sound file (now represented by a Shape object, the icon) over to above the upper left hand corner of the slide. Then it sets several properties of the AnimationSettings object, which controls the playback behavior of the sound file. Specifically, the sound file is set to be the first shape on the slide animated, but to have no entry effect (so it just appears—or rather, doesn’t, as it’s positioned off the slide), and to play as soon as it appears, which is when the slide appears.
Sub AddAudioOffSlide()
Dim shpSound As Shape
With ActivePresentation.Slides(2).Shapes
Set shpSound = .AddMediaObject _
("C:\soundfiles\pixies\wave_of_mutilation.mp3")
With shpSound
.Left = 0 - .Width
.Top = 0 - .Height
With .AnimationSettings
.Animate = msoTrue
.AnimationOrder = 1
.EntryEffect = ppEffectNone
.PlaySettings.PlayOnEntry = msoTrue
.AdvanceMode = ppAdvanceOnTime
.AdvanceTime = 0
End With
End With
End With
End Sub
I believe you could also set the sound file to play in conjunction with another shape’s animation by setting the AnimationSettings.AnimationOrder of both Shape objects to the same value, but I haven’t tested that. And anyway, if you just wanted to play the sound file once as part of another shape’s animation, you can just use the AnimationSettings.SoundEffect property to do that, without having to add the sound file to the slide at all.
Comments
- Anonymous
May 04, 2004
Hi AJ,
Setting the AnimationSettings.AnimationOrder of both Shape objects to the same value won't work in 97/2000 since they did not support 'With Previous' trigger. So two animations could not fire simultaneously. In PowerPoint 2002/2003 you would avoid using the AnimationSettings object altogether and use the Timeline object instead. - Anonymous
May 04, 2004
Shyam, Welcome! Thanks for the clarification that PowerPoint 97/2000 doesn't support the 'With Previous'animation trigger. That makes my batting average for this entry a perfect 000. As for using the TimeLine object instead of AnimationSettings in PowerPoint 2002/2003, see my belated mea culpa here: http://blogs.msdn.com/andrew_may/archive/2004/03/24/95613.aspx
For everyone else out there, Shyam is one of our wonderful PowerPoint MVPs, with extensive experience in PowerPoint animation. Check out the great stuff he's got available at his PowerPoint site: http://www.mvps.org/skp/ - Anonymous
June 02, 2009
PingBack from http://woodtvstand.info/story.php?id=84508