' イベントの編集。終了 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Me.PlayerStop() End Sub ''' <summary> ''' メソッドの追加。再生状態のときに、プレイヤーを終了する。 ''' </summary> Private Sub PlayerStop() ' 再生中 Const STRING_PLAY_STATE_PLAYING As String = "playing" ' 再生状態 Dim strMode As String = objMciCmd.PlayStateResult(STR_ALIAS) Console.WriteLine(strMode) If strMode.Equals(STRING_PLAY_STATE_PLAYING) Then objMciCmd.PlayerStop(STR_ALIAS) End If End Sub
''' <summary> ''' 追加。再生状態を取得する。 ''' </summary> ''' <param name="strAlias">エイリアス名</param> ''' <returns>再生状態</returns> Public Function PlayStateResult(ByVal strAlias As String) As String ' バッファー Dim strBuf As String = New String(Chr(0), 255) ' 再生状態 Dim strMode As String = String.Empty ' コマンド Dim strCmd As String = String.Empty strCmd = String.Concat("status ", strAlias, " mode") Call mciSendString(strCmd, strBuf, strBuf.Length, 0) strMode = strBuf.Replace(Chr(0), "") Return strMode End Function