' 确保已经将AxWindowsMediaPlayer控件添加到了窗体上,并命名为axWindowsMediaPlayer ' 在窗体的类中添加PlayStateChange事件的处理程序 Private Sub axWindowsMediaPlayer_PlayStateChange(sender As Object, e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles axWindowsMediaPlayer.PlayStateChange If (e.newState = 1) Then ' 1 表示媒体播放结束 Dim counter As Integer = CType(axWindowsMediaPlayer.CtlControls.get_Item("PlayCount"), Integer) If counter >= 2 Then ' 循环播放了3次 axWindowsMediaPlayer.Ctlcontrols.stop() ' 停止播放 End If End If End Sub ' 播放媒体文件的函数 Private Sub PlayMediaFileLooped3Times(filePath As String) axWindowsMediaPlayer.URL = filePath ' 设置媒体文件路径 axWindowsMediaPlayer.settings.setMode("loop", True) ' 设置循环模式 axWindowsMediaPlayer.Ctlcontrols.playCount = 3 ' 设置播放次数为3 axWindowsMediaPlayer.Ctlcontrols.play() ' 播放媒体文件 End Sub ' 在需要的时候调用PlayMediaFileLooped3Times函数 Private Sub ButtonPlay_Click(sender As Object, e As EventArgs) Handles ButtonPlay.Click PlayMediaFileLooped3Times("你的媒体文件路径.mp3") ' 替换为实际路径 End Sub
标签:End,Sub,媒体文件,axWindowsMediaPlayer,循环,播放,PlayStateChange From: https://www.cnblogs.com/Sunshine-bing/p/18546225