Imports System.Runtime.InteropServices
Imports System.IO
Public Class Form1
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
Private Declare Function GetTickCount Lib "kernel32" () As Integer
Dim numbers() As String '定义全局变量,用于存储分割后的数字字符串
Dim index As Integer = 0 '定义全局变量,用于记录当前播放的MP3文件和显示的图片的索引
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim input As String = TextBox1.Text
numbers = input.Split(New Char() {"."}) '将输入的数字字符串以逗号分割为多个字符串数字
PlayMP3AndShowImage() '调用播放MP3和显示图片的方法
End Sub
Private Sub PlayMP3AndShowImage()
Dim number As String = numbers(index) '获取当前索引对应的数字字符串
Select Case number
Case "1"
PictureBox1.Image = Image.FromFile(Path.Combine(Application.StartupPath, "C:\Users\Administrator\Documents\Visual Studio 2010\Projects\c\1.jpeg")) '显示第1个字符串对应的图片
PlayMP3(Path.Combine(Application.StartupPath, "C:\Users\Administrator\Documents\Visual Studio 2010\Projects\c\1.MP3")) '播放第1个字符串对应的MP3文件
Case "2"
PictureBox1.Image = Image.FromFile(Path.Combine(Application.StartupPath, "C:\Users\Administrator\Documents\Visual Studio 2010\Projects\c\2.jpeg")) '显示第2个字符串对应的图片
PlayMP3(Path.Combine(Application.StartupPath, "C:\Users\Administrator\Documents\Visual Studio 2010\Projects\c\2.MP3")) '播放第2个字符串对应的MP3文件
Case "3"
PictureBox1.Image = Image.FromFile(Path.Combine(Application.StartupPath, "C:\Users\Administrator\Documents\Visual Studio 2010\Projects\c\3.jpeg")) '显示第3个字符串对应的图片
PlayMP3(Path.Combine(Application.StartupPath, "C:\Users\Administrator\Documents\Visual Studio 2010\Projects\c\3.MP3")) '播放第3个字符串对应的MP3文件
'根据需要继续添加其他数字字符串对应的图片和MP3文件的情况
End Select
index += 1 '将索引加1,以便下一次播放下一个MP3文件和显示下一个图片
If index >= numbers.Length Then '如果当前索引超过了数字字符串数组的长度,则将索引重置为0,循环播放
index = 0
End If
End Sub
Private Sub PlayMP3(ByVal filePath As String)
Dim command As String = "open """ & filePath & """ type mpegvideo alias mp3" '构建MCI命令,打开指定的MP3文件并创建别名
mciSendString(command, "", 0, 0) '发送MCI命令
command = "play mp3" '构建MCI命令,播放MP3文件
mciSendString(command, "", 0, 0) '发送MCI命令
Dim startTime As Integer = GetTickCount() '记录开始播放的时间
Do While GetTickCount() - startTime < 300 '等待1秒钟
Application.DoEvents() '处理其他消息,保持界面响应
Loop
command = "stop mp3" '构建MCI命令,停止播放MP3文件
mciSendString(command, "", 0, 0) '发送MCI命令
command = "close mp3" '构建MCI命令,关闭MP3文件
mciSendString(command, "", 0, 0) '发送MCI命令
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.Text = "1.2.3"
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim input As String = TextBox1.Text
numbers = input.Split(New Char() {"."}) '将输入的数字字符串以逗号分割为多个字符串数字
PlayMP3AndShowImage() '调用播放MP3和显示图片的方法
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Start()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Timer1.Stop()
End Sub
End Class