【问题标题】:Stop playing sound media on click单击时停止播放声音媒体
【发布时间】:2020-07-13 20:42:14
【问题描述】:

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

幻灯片时间线将是:

  1. 第一次点击开始播放声音
  2. 第二次点击停止第一个声音并开始第二个声音。

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

我找不到复制 GUI 选项以停止点击播放的效果对象属性。

代码将添加一张新幻灯片,创建两个声音形状并让它们在点击时触发,但声音 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

我检查了 Effect 和 Timeline 对象的属性,但找不到这个。

【问题讨论】:

    标签: vba powerpoint


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多