单击停止播放声音媒体

时间:2020-05-08 04:08:29

标签: vba powerpoint

我想使用PowerPoint VBA(Microsoft 365 MSO)向PowerPoint幻灯片中添加两个声音形状,都在单击时触发。

幻灯片时间轴将是:

  1. 第一次单击将开始播放声音
  2. 第二次单击将停止第一个声音,然后开始第二个声音。

我能够放置声音形状并添加动画对象以触发声音。

我找不到复制GUI选项以停止单击播放的效果对象属性。
GUI option to stop playing on click

代码将添加一个新的幻灯片,创建两个声音形状,并在单击时触发它们,但是声音1不会停止播放。

Sub TestSoundTrigger()

    Dim slTestSoundSlide As Slide
    Dim shSoundShape1 As Shape
    Dim shSoundShape2 As Shape
    Dim efSoundShape1 As Effect
    Dim efSoundShape2 As Effect

' Create the slide
    Set slTestSoundSlide = ActivePresentation.Slides.AddSlide(ActivePresentation.Slides.Count + 1, ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1))

' Add 2 sound shapes
    Set shSoundShape1 = slTestSoundSlide.Shapes.AddMediaObject2(ActivePresentation.Path & "\testsound1.mp3", True, False, 10, 10)
    Set shSoundShape2 = slTestSoundSlide.Shapes.AddMediaObject2(ActivePresentation.Path & "\testsound2.mp3", True, False, 10, 10)
    
' Add the 2 triggers to play the sounds on click in turn
    Set efSoundShape1 = slTestSoundSlide.TimeLine.MainSequence.AddEffect(shSoundShape1, effectId:=msoAnimEffectMediaPlay)
    Set efSoundShape2 = slTestSoundSlide.TimeLine.MainSequence.AddEffect(shSoundShape2, effectId:=msoAnimEffectMediaPlay)

End Sub

我已经检查了“效果”和“时间轴”对象的属性,但是找不到该属性。

1 个答案:

答案 0 :(得分:1)

我找到了此属性:ppSoundStopPrevious ppSoundEffectType

或者 您可以设置另一个msoAnimEffectMediaStop-但这将创建另一个动画步骤

    Sub TestSoundTrigger()

    Dim slTestSoundSlide As Slide
    Dim shSoundShape1 As Shape
    Dim shSoundShape2 As Shape
    Dim efSoundShape1 As Effect
    Dim efSoundShape2 As Effect

' Create the slide
    Set slTestSoundSlide = ActivePresentation.Slides.AddSlide(ActivePresentation.Slides.Count + 1, ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1))

' Add 2 sound shapes
    Set shSoundShape1 = slTestSoundSlide.Shapes.AddMediaObject2(ActivePresentation.Path & "\testsound1.mp3", True, False, 10, 10)
    Set shSoundShape2 = slTestSoundSlide.Shapes.AddMediaObject2(ActivePresentation.Path & "\testsound2.mp3", True, False, 10, 10)

' Add the 2 triggers to play the sounds on click in turn
    Set efSoundShape1 = slTestSoundSlide.TimeLine.MainSequence.AddEffect(shSoundShape1, effectId:=msoAnimEffectMediaPlay)
    Set efSoundShape1 = slTestSoundSlide.TimeLine.MainSequence.AddEffect(shSoundShape1, effectId:=msoAnimEffectMediaStop)
    Set efSoundShape2 = slTestSoundSlide.TimeLine.MainSequence.AddEffect(shSoundShape2, effectId:=msoAnimEffectMediaPlay)

End Sub
相关问题