我正在开发PowerPoint2007VSTO加载项,我正在运行一个小问题。加载项使用以下代码向当前幻灯片添加声音:
var shape = slide.Shapes.AddMediaObject(soundFileLocation, 50, 50, 20, 20);
生成的形状确实有声音,可以通过PowerPoint幻灯片播放。我的问题是,如果引用了以这种方式创建的形状,我希望以编程方式播放声音,但找不到方法。我试过
var soundEffect = shape.AnimationSettings.SoundEffect;
soundEffect.Play();
但这失败/崩溃了,当我检查SoundEffect时,它的类型是ppSoundNone。
编辑:
取得了部分成功
var shape = slide.Shapes.AddMediaObject(fileLocation, 50, 50, 20, 20);
shape.AnimationSettings.SoundEffect.ImportFromFile(fileLocation);
这样做可以让我播放声音:
var animationSettings = shape.AnimationSettings;
var soundEffect = shape.AnimationSettings.SoundEffect;
soundEffect.Play();
但是有一个主要问题;这只适用于添加的最后一个形状。出于某种原因,shape.animationsettings.soundeffect.importfromfile(filelocation)似乎将先前创建的形状的soundeffect属性重置为ppsoundnone…
如果这样做不可行,我会很惊讶,但我似乎找不到方法——任何帮助都会非常感谢!