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
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim input As String = TextBox1.Text.Trim() ' 获取文本框中的字符串
Dim strings As String() = input.Split(","c) ' 将字符串按逗号分割为多个字符串
For Each str As String In strings
Select Case str.ToLower()
Case "1"
PlayMP3("1.mp3") ' 播放对应的MP3文件
Case "2"
PlayMP3("2.mp3") ' 播放对应的MP3文件
Case "3"
PlayMP3("3.mp3") ' 播放对应的MP3文件
Case "4"
PlayMP3("4.mp3") ' 播放对应的MP3文件
Case "5"
PlayMP3("5.mp3") ' 播放对应的MP3文件
Case "6"
PlayMP3("6.mp3") ' 播放对应的MP3文件
Case "7"
PlayMP3("7.mp3") ' 播放对应的MP3文件
Case "-"
PlayMP3("0.wav") ' 播放对应的MP3文件
' 添加其他字符串对应的播放操作
Case Else
' 处理其他字符串
End Select
Next
End Sub
Private Sub SetVolume(ByVal volume As Integer)
Dim command As String = "setaudio ""all"" volume to " & volume
mciSendString(command, Nothing, 0, 0)
End Sub
Private Sub PlayMP3(ByVal filename As String)
Dim command As String = "open """ & filename & """ type mpegvideo alias mp3" ' 打开MP3文件
mciSendString(command, Nothing, 0, 0)
command = "play mp3" ' 播放MP3文件
mciSendString(command, Nothing, 0, 0)
' 等待播放完成
Dim startTick As Integer = GetTickCount()
Do While GetTickCount() - startTick < 200 ' 等待1秒钟
Application.DoEvents()
Loop
command = "close mp3" ' 关闭MP3文件
mciSendString(command, Nothing, 0, 0)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.Text = "1,1,5,5,6,6,5,-,-,4,4,3,3,2,2,1,-,-,5,5,4,4,3,3,2,-,-,5,5,4,4,3,3,2,-,-,1,1,5,5,6,6,5,-,-,,4,4,3,3,2,2,1,-,-,-,"
' 将音量设置为 50%
SetVolume(100)
End Sub
End Class
…
…
…
这款软件是播放MP3声音文件的功能,每个mp3都是一个音符,然后我们通过编写简谱即可播放音乐,就像钢琴简谱播放器那样的简易功能。
🎉精彩不容错过!新文章震撼登场,却因代码不全让人意犹未尽?别担心!我们为你准备了软件截图,让你先睹为快,感受其强大魅力。
✨如果你渴望解锁全部精彩内容,那么强烈建议你下载完整源代码。它将为你打开一扇通往编程新世界的大门,让你深入探索其中的奥秘,挖掘无限潜力。
🔗源代码下载网址:[https://download.csdn.net/download/qq_32257509/89642361]。赶紧行动起来,下载完整源代码,开启你的编程之旅吧!