在 Powerpoint VBA 中,如何让嵌入的视频开始播放?

In Powerpoint VBA, how do I make an embedded video start playing?

我的 Office 365 PowerPoint 演示文稿只有一张幻灯片。该幻灯片包含一个带有嵌入(未链接,非 OLE)视频的形状,我最初是从 .mp4 文件中插入的。当我点击它时视频开始播放,但我需要从 VBA 代码控制它。我尝试过的任何东西(见下文)都不起作用,当然我也没有收到任何错误消息或任何类型的反馈。如何从代码开始(和停止)视频?

Sub PlayVideo(Name)
Set Shape = GetShape(Name)
' Shape.MediaType == ppMediaTypeMovie

With Shape.AnimationSettings
    .Animate = msoTrue
    .AdvanceMode = ppAdvanceOnTime
    .AdvanceTime = 0
    .TextLevelEffect = ppAnimateByAllLevels
    With .PlaySettings
        .PlayOnEntry = msoTrue
        .PauseAnimation = msoFalse
        .LoopUntilStopped = msoTrue
    End With
End With
With Slide.TimeLine.MainSequence
    Set AnimationEffect = .AddEffect(Shape:=Shape, effectid:=msoAnimEffectMediaPlay)
    With AnimationEffect
        Set Behaviour = .Behaviors.Add(msoAnimTypeCommand)
        With Behaviour
            .CommandEffect.Type = msoAnimCommandTypeVerb
            .CommandEffect.Command = "play"
        End With
    End With
End With
End Sub

开始视频使用

SlideShowWindows(1).View.Player("algorithm panel").Play

停止视频使用

SlideShowWindows(1).View.Player("algorithm panel").Stop

这是一个例子。将其粘贴到模块中。我的视频名称是 SAMPLE.mp4

Option Explicit

Sub StartVideo()
    SlideShowWindows(1).View.Player("SAMPLE").Play
End Sub

Sub StopVideo()
    SlideShowWindows(1).View.Player("SAMPLE").Stop
End Sub

接下来在幻灯片中插入 2 个操作按钮并分配宏

我们完成了。