Declare Auto Function PlaySound Lib "winmm.dll" (ByVal lpszSoundName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer
Const SND_FILENAME As Integer = &H20000
Const SND_ALIAS As Integer = &H10000
Const SND_SYNC As Integer = &H0
Const SND_ASYNC = &H1
在窗体的按钮点击事件里写如下代码:
Dim mstrfileName As String = Application.StartupPath & "\Alarm.wav"
PlaySound(mstrfileName, 0, SND_FILENAME Or SND_SYNC)
这里参数采用SND_SYNC表示同步,SND_ASYNC表示异步,采用上面的代码写法在点击按钮时不会中断当前播放的声音而顺序播放,但是因为同步的原因,界面得等到播放结束后才能进行其他操作。
现在问如何才能既保证不会中断当前播放声音而重新从头开始播放,并且也不影响界面其他操作
10 个解决方案
#1
up
#2
你这个现象我遇到过,调用一个线程就可以了!把你读音的代码放到线程里面!
在事件里面再1启动这个线程就可以了
Public BWeditTXTThead As New Thread(AddressOf TheadthingProc) '定义一个线程
TheadthingProc为线程名称
BWeditTXTThead.stard
下次继续使用此线程时需要初始化一下线程即可!
TTBJ.BWeditTXTThead = New Thread(AddressOf TTBJ.TheadthingProc) '初始化一下线程
在事件里面再1启动这个线程就可以了
Public BWeditTXTThead As New Thread(AddressOf TheadthingProc) '定义一个线程
TheadthingProc为线程名称
BWeditTXTThead.stard
下次继续使用此线程时需要初始化一下线程即可!
TTBJ.BWeditTXTThead = New Thread(AddressOf TTBJ.TheadthingProc) '初始化一下线程
#3
顶你!
#4
starring(漂流⊙一组) 的方法可行,如果不用多线程如何处理
#5
帮顶
#6
开始我也是遇到你这样的难题了,在读音的时候想处理其他的东西,只能用任务管理器强行结束程序了,其他的没有解决的方法。想了一遍感觉线程处理比较好一些。我感觉这个读音这个过程就是同步的原因,如果不用线程的话,系统只能处理当前的数据,而不能进行其他数据的处理了,就象你描述的那样,这个读音过程不结束,其他的事件就不能给予处理了,所以我建议还是用线程处理比较好一些,而且用线程处理的话,不影响你处理其他的东西。
至于你说的其他的方法 我没想到而且感觉处理也不如线程处理方便。
今晚喝多了,随便说一些比着边际的东西,别见怪!
至于你说的其他的方法 我没想到而且感觉处理也不如线程处理方便。
今晚喝多了,随便说一些比着边际的东西,别见怪!
#7
兄弟这是我做的一个播放器的代码,希望能帮上你的忙!
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
Dim s2, s1, s3 As String
Dim s4, s5 As String
Dim s6 As Byte
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
If List1.SelectedIndex < 0 Then List1.SelectedIndex = 0
Call Read_TAG(VB6.GetItemString(List1, List1.SelectedIndex), s1, s2, s3, s4, s5, s6) : Call Show_Tag()
MPlayer1.FileName = VB6.GetItemString(List1, List1.SelectedIndex)
MPlayer1.Play()
Label4.Text = Text1(0).Text
Picture1.Visible = True : Timer2.Enabled = True
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
MPlayer1.Stop()
Picture1.Visible = False : Timer2.Enabled = False
End Sub
Private Sub Command3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command3.Click
Try
Dim f As String
Dim Result As Windows.Forms.DialogResult
'设置对话框标题
OpenFileDialog1.Title = "打开文件"
'设置Filter文件筛选器
OpenFileDialog1.Filter = "MP3格式(*.MP3)|*.MP3|wav格式(*.wav)|*.wav|mid格式(*.mid)|*.mid|所有文件(*.*)|*.*"
'打开对话框,注意标准对话框都是有模式的打开
Result = OpenFileDialog1.ShowDialog()
'如果单击了“打开”按钮并且FileName不为空时,打开RichTextBox文件
If Result = DialogResult.OK And Len(OpenFileDialog1.FileName) > 0 Then
Me.Label1.Text = OpenFileDialog1.FileName
End If
If OpenFileDialog1.FileName <> "" Then
f = OpenFileDialog1.FileName
List1.Items.Add(f)
End If
'End With
Catch Exc As System.OverflowException
MsgBox("aaaaaaaaaaaa")
End Try
End Sub
Private Sub Command4_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command4.Click
If List1.SelectedIndex < 0 Then Exit Sub
List1.Items.RemoveAt(List1.SelectedIndex)
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim i As Short
Dim s As String
MPlayer1.Visible = False
Slider1.Value = MPlayer1.Volume
For i = 0 To 32000
s = INIReadString("列表框", "歌曲" & i, "", VB6.GetPath & "\song.ini")
If s = "" Then Exit For
List1.Items.Add(s)
Next i
Me.Text = System.Reflection.Assembly.GetExecutingAssembly.GetName.Name
End Sub
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
Dim s2, s1, s3 As String
Dim s4, s5 As String
Dim s6 As Byte
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
If List1.SelectedIndex < 0 Then List1.SelectedIndex = 0
Call Read_TAG(VB6.GetItemString(List1, List1.SelectedIndex), s1, s2, s3, s4, s5, s6) : Call Show_Tag()
MPlayer1.FileName = VB6.GetItemString(List1, List1.SelectedIndex)
MPlayer1.Play()
Label4.Text = Text1(0).Text
Picture1.Visible = True : Timer2.Enabled = True
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
MPlayer1.Stop()
Picture1.Visible = False : Timer2.Enabled = False
End Sub
Private Sub Command3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command3.Click
Try
Dim f As String
Dim Result As Windows.Forms.DialogResult
'设置对话框标题
OpenFileDialog1.Title = "打开文件"
'设置Filter文件筛选器
OpenFileDialog1.Filter = "MP3格式(*.MP3)|*.MP3|wav格式(*.wav)|*.wav|mid格式(*.mid)|*.mid|所有文件(*.*)|*.*"
'打开对话框,注意标准对话框都是有模式的打开
Result = OpenFileDialog1.ShowDialog()
'如果单击了“打开”按钮并且FileName不为空时,打开RichTextBox文件
If Result = DialogResult.OK And Len(OpenFileDialog1.FileName) > 0 Then
Me.Label1.Text = OpenFileDialog1.FileName
End If
If OpenFileDialog1.FileName <> "" Then
f = OpenFileDialog1.FileName
List1.Items.Add(f)
End If
'End With
Catch Exc As System.OverflowException
MsgBox("aaaaaaaaaaaa")
End Try
End Sub
Private Sub Command4_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command4.Click
If List1.SelectedIndex < 0 Then Exit Sub
List1.Items.RemoveAt(List1.SelectedIndex)
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim i As Short
Dim s As String
MPlayer1.Visible = False
Slider1.Value = MPlayer1.Volume
For i = 0 To 32000
s = INIReadString("列表框", "歌曲" & i, "", VB6.GetPath & "\song.ini")
If s = "" Then Exit For
List1.Items.Add(s)
Next i
Me.Text = System.Reflection.Assembly.GetExecutingAssembly.GetName.Name
End Sub
#8
接着上楼的!
Private Sub Form1_Closed(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed
Dim i As Short
For i = 0 To List1.Items.Count - 1
Call INIWriteString("列表框", "歌曲" & i, VB6.GetItemString(List1, i), VB6.GetPath & "\song.ini")
Next i
End Sub
Private Sub List1_DoubleClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles List1.DoubleClick
Call Command1_Click(Command1, New System.EventArgs)
End Sub
Private Sub MPlayer1_EndOfStream(ByVal result As Integer)
Dim i As Short
i = List1.SelectedIndex
i = i + 1
If i > List1.Items.Count - 1 Then i = 0
List1.SelectedIndex = i
MPlayer1.FileName = VB6.GetItemString(List1, List1.SelectedIndex)
Call Read_TAG(MPlayer1.FileName, s1, s2, s3, s4, s5, s6) : Call Show_Tag()
Label4.Text = Text1(0).Text
End Sub
Sub Show_Tag()
Text1(0).Text = s1 '歌名
Text1(1).Text = s2 '歌星
Text1(2).Text = s3 '专辑
Text1(3).Text = s4 '出版年
Text1(4).Text = s5 '说明
Text1(5).Text = CStr(s6) '校验码
End Sub
Private Sub Slider1_Scroll(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Slider1.Scroll
MPlayer1.Volume = Slider1.Value - 2500
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
Dim d1, d2 As Short
Dim m1, s1 As Short
Dim m2, s2 As Short
d1 = MPlayer1.CurrentPosition
d2 = MPlayer1.Duration
m1 = d1 \ 60
s1 = d1 Mod 60
m2 = d2 \ 60
s2 = d2 Mod 60
Label3.Text = m1 & ":" & VB6.Format(s1, "00") & " (" & m2 & ":" & VB6.Format(s2, "00") & ")"
End Sub
Private Sub Timer2_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer2.Tick
If VB6.PixelsToTwipsX(Label4.Left) < 0 - VB6.PixelsToTwipsX(Label4.Width) Then
Label4.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Picture1.Width) - 1)
Label4.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Label4.Left) - 5)
Else
Label4.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Label4.Left) - 10)
End If
End Sub
Function Read_TAG(ByRef fname As String, ByRef 歌名 As String, ByRef 歌星 As String, ByRef 专辑名称 As String, ByRef 出版年 As String, ByRef 说明 As String, ByRef 校验码 As Byte)
Dim i As Short, j As Short
Dim k As String
i = FreeFile()
Dim x(127) As Byte
FileOpen(i, fname, OpenMode.Binary, OpenAccess.Read)
'跳到倒数第128位元组
Seek(i, LOF(i) - 127)
'读取127个字符
FileGet(i, x)
'关闭文件
FileClose(i)
If LCase(Chr(x(0)) & Chr(x(1)) & Chr(x(2))) <> "tag" Then
Read_TAG = False
歌名 = ""
歌星 = ""
专辑名称 = ""
出版年 = ""
说明 = ""
校验码 = 0
Exit Function
End If
歌名 = ""
For j = 3 To 32
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
歌名 = 歌名 + k
Next
歌星 = ""
For j = 33 To 62
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
歌星 = 歌星 + k
Next
专辑名称 = ""
For j = 63 To 92
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
专辑名称 = 专辑名称 + k
Next
出版年 = ""
For j = 93 To 96
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
出版年 = 出版年 + k
Next
说明 = ""
For j = 97 To 126
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
说明 = 说明 + k
Next
校验码 = x(127)
Read_TAG = True
End Function
Function INIReadString(ByRef app As String, ByRef keyw As String, ByRef val_Renamed As String, ByRef inifile As String) As String
Dim i As Integer
Dim k As String
k = New String(" ", 255)
i = GetPrivateProfileString(app, keyw, val_Renamed, k, Len(k), inifile)
k = Trim(k) : k = VB.Left(k, Len(k) - 1)
INIReadString = k
End Function
Sub INIWriteString(ByRef app As String, ByRef keyw As String, ByRef val_Renamed As String, ByRef inifile As String)
Dim xx As Short
xx = WritePrivateProfileString(app, keyw, val_Renamed, inifile)
End Sub
Private Sub Form1_Closed(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed
Dim i As Short
For i = 0 To List1.Items.Count - 1
Call INIWriteString("列表框", "歌曲" & i, VB6.GetItemString(List1, i), VB6.GetPath & "\song.ini")
Next i
End Sub
Private Sub List1_DoubleClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles List1.DoubleClick
Call Command1_Click(Command1, New System.EventArgs)
End Sub
Private Sub MPlayer1_EndOfStream(ByVal result As Integer)
Dim i As Short
i = List1.SelectedIndex
i = i + 1
If i > List1.Items.Count - 1 Then i = 0
List1.SelectedIndex = i
MPlayer1.FileName = VB6.GetItemString(List1, List1.SelectedIndex)
Call Read_TAG(MPlayer1.FileName, s1, s2, s3, s4, s5, s6) : Call Show_Tag()
Label4.Text = Text1(0).Text
End Sub
Sub Show_Tag()
Text1(0).Text = s1 '歌名
Text1(1).Text = s2 '歌星
Text1(2).Text = s3 '专辑
Text1(3).Text = s4 '出版年
Text1(4).Text = s5 '说明
Text1(5).Text = CStr(s6) '校验码
End Sub
Private Sub Slider1_Scroll(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Slider1.Scroll
MPlayer1.Volume = Slider1.Value - 2500
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
Dim d1, d2 As Short
Dim m1, s1 As Short
Dim m2, s2 As Short
d1 = MPlayer1.CurrentPosition
d2 = MPlayer1.Duration
m1 = d1 \ 60
s1 = d1 Mod 60
m2 = d2 \ 60
s2 = d2 Mod 60
Label3.Text = m1 & ":" & VB6.Format(s1, "00") & " (" & m2 & ":" & VB6.Format(s2, "00") & ")"
End Sub
Private Sub Timer2_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer2.Tick
If VB6.PixelsToTwipsX(Label4.Left) < 0 - VB6.PixelsToTwipsX(Label4.Width) Then
Label4.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Picture1.Width) - 1)
Label4.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Label4.Left) - 5)
Else
Label4.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Label4.Left) - 10)
End If
End Sub
Function Read_TAG(ByRef fname As String, ByRef 歌名 As String, ByRef 歌星 As String, ByRef 专辑名称 As String, ByRef 出版年 As String, ByRef 说明 As String, ByRef 校验码 As Byte)
Dim i As Short, j As Short
Dim k As String
i = FreeFile()
Dim x(127) As Byte
FileOpen(i, fname, OpenMode.Binary, OpenAccess.Read)
'跳到倒数第128位元组
Seek(i, LOF(i) - 127)
'读取127个字符
FileGet(i, x)
'关闭文件
FileClose(i)
If LCase(Chr(x(0)) & Chr(x(1)) & Chr(x(2))) <> "tag" Then
Read_TAG = False
歌名 = ""
歌星 = ""
专辑名称 = ""
出版年 = ""
说明 = ""
校验码 = 0
Exit Function
End If
歌名 = ""
For j = 3 To 32
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
歌名 = 歌名 + k
Next
歌星 = ""
For j = 33 To 62
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
歌星 = 歌星 + k
Next
专辑名称 = ""
For j = 63 To 92
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
专辑名称 = 专辑名称 + k
Next
出版年 = ""
For j = 93 To 96
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
出版年 = 出版年 + k
Next
说明 = ""
For j = 97 To 126
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
说明 = 说明 + k
Next
校验码 = x(127)
Read_TAG = True
End Function
Function INIReadString(ByRef app As String, ByRef keyw As String, ByRef val_Renamed As String, ByRef inifile As String) As String
Dim i As Integer
Dim k As String
k = New String(" ", 255)
i = GetPrivateProfileString(app, keyw, val_Renamed, k, Len(k), inifile)
k = Trim(k) : k = VB.Left(k, Len(k) - 1)
INIReadString = k
End Function
Sub INIWriteString(ByRef app As String, ByRef keyw As String, ByRef val_Renamed As String, ByRef inifile As String)
Dim xx As Short
xx = WritePrivateProfileString(app, keyw, val_Renamed, inifile)
End Sub
#9
这是之前的相关声明
Option Strict Off
Option Explicit On
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.IO
Imports VB = Microsoft.VisualBasic
楼主如果还看不明白!我的电子邮件是SNRMNM_SX@163.COM
Option Strict Off
Option Explicit On
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.IO
Imports VB = Microsoft.VisualBasic
楼主如果还看不明白!我的电子邮件是SNRMNM_SX@163.COM
#10
牛的!
#1
up
#2
你这个现象我遇到过,调用一个线程就可以了!把你读音的代码放到线程里面!
在事件里面再1启动这个线程就可以了
Public BWeditTXTThead As New Thread(AddressOf TheadthingProc) '定义一个线程
TheadthingProc为线程名称
BWeditTXTThead.stard
下次继续使用此线程时需要初始化一下线程即可!
TTBJ.BWeditTXTThead = New Thread(AddressOf TTBJ.TheadthingProc) '初始化一下线程
在事件里面再1启动这个线程就可以了
Public BWeditTXTThead As New Thread(AddressOf TheadthingProc) '定义一个线程
TheadthingProc为线程名称
BWeditTXTThead.stard
下次继续使用此线程时需要初始化一下线程即可!
TTBJ.BWeditTXTThead = New Thread(AddressOf TTBJ.TheadthingProc) '初始化一下线程
#3
顶你!
#4
starring(漂流⊙一组) 的方法可行,如果不用多线程如何处理
#5
帮顶
#6
开始我也是遇到你这样的难题了,在读音的时候想处理其他的东西,只能用任务管理器强行结束程序了,其他的没有解决的方法。想了一遍感觉线程处理比较好一些。我感觉这个读音这个过程就是同步的原因,如果不用线程的话,系统只能处理当前的数据,而不能进行其他数据的处理了,就象你描述的那样,这个读音过程不结束,其他的事件就不能给予处理了,所以我建议还是用线程处理比较好一些,而且用线程处理的话,不影响你处理其他的东西。
至于你说的其他的方法 我没想到而且感觉处理也不如线程处理方便。
今晚喝多了,随便说一些比着边际的东西,别见怪!
至于你说的其他的方法 我没想到而且感觉处理也不如线程处理方便。
今晚喝多了,随便说一些比着边际的东西,别见怪!
#7
兄弟这是我做的一个播放器的代码,希望能帮上你的忙!
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
Dim s2, s1, s3 As String
Dim s4, s5 As String
Dim s6 As Byte
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
If List1.SelectedIndex < 0 Then List1.SelectedIndex = 0
Call Read_TAG(VB6.GetItemString(List1, List1.SelectedIndex), s1, s2, s3, s4, s5, s6) : Call Show_Tag()
MPlayer1.FileName = VB6.GetItemString(List1, List1.SelectedIndex)
MPlayer1.Play()
Label4.Text = Text1(0).Text
Picture1.Visible = True : Timer2.Enabled = True
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
MPlayer1.Stop()
Picture1.Visible = False : Timer2.Enabled = False
End Sub
Private Sub Command3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command3.Click
Try
Dim f As String
Dim Result As Windows.Forms.DialogResult
'设置对话框标题
OpenFileDialog1.Title = "打开文件"
'设置Filter文件筛选器
OpenFileDialog1.Filter = "MP3格式(*.MP3)|*.MP3|wav格式(*.wav)|*.wav|mid格式(*.mid)|*.mid|所有文件(*.*)|*.*"
'打开对话框,注意标准对话框都是有模式的打开
Result = OpenFileDialog1.ShowDialog()
'如果单击了“打开”按钮并且FileName不为空时,打开RichTextBox文件
If Result = DialogResult.OK And Len(OpenFileDialog1.FileName) > 0 Then
Me.Label1.Text = OpenFileDialog1.FileName
End If
If OpenFileDialog1.FileName <> "" Then
f = OpenFileDialog1.FileName
List1.Items.Add(f)
End If
'End With
Catch Exc As System.OverflowException
MsgBox("aaaaaaaaaaaa")
End Try
End Sub
Private Sub Command4_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command4.Click
If List1.SelectedIndex < 0 Then Exit Sub
List1.Items.RemoveAt(List1.SelectedIndex)
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim i As Short
Dim s As String
MPlayer1.Visible = False
Slider1.Value = MPlayer1.Volume
For i = 0 To 32000
s = INIReadString("列表框", "歌曲" & i, "", VB6.GetPath & "\song.ini")
If s = "" Then Exit For
List1.Items.Add(s)
Next i
Me.Text = System.Reflection.Assembly.GetExecutingAssembly.GetName.Name
End Sub
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
Dim s2, s1, s3 As String
Dim s4, s5 As String
Dim s6 As Byte
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
If List1.SelectedIndex < 0 Then List1.SelectedIndex = 0
Call Read_TAG(VB6.GetItemString(List1, List1.SelectedIndex), s1, s2, s3, s4, s5, s6) : Call Show_Tag()
MPlayer1.FileName = VB6.GetItemString(List1, List1.SelectedIndex)
MPlayer1.Play()
Label4.Text = Text1(0).Text
Picture1.Visible = True : Timer2.Enabled = True
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
MPlayer1.Stop()
Picture1.Visible = False : Timer2.Enabled = False
End Sub
Private Sub Command3_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command3.Click
Try
Dim f As String
Dim Result As Windows.Forms.DialogResult
'设置对话框标题
OpenFileDialog1.Title = "打开文件"
'设置Filter文件筛选器
OpenFileDialog1.Filter = "MP3格式(*.MP3)|*.MP3|wav格式(*.wav)|*.wav|mid格式(*.mid)|*.mid|所有文件(*.*)|*.*"
'打开对话框,注意标准对话框都是有模式的打开
Result = OpenFileDialog1.ShowDialog()
'如果单击了“打开”按钮并且FileName不为空时,打开RichTextBox文件
If Result = DialogResult.OK And Len(OpenFileDialog1.FileName) > 0 Then
Me.Label1.Text = OpenFileDialog1.FileName
End If
If OpenFileDialog1.FileName <> "" Then
f = OpenFileDialog1.FileName
List1.Items.Add(f)
End If
'End With
Catch Exc As System.OverflowException
MsgBox("aaaaaaaaaaaa")
End Try
End Sub
Private Sub Command4_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command4.Click
If List1.SelectedIndex < 0 Then Exit Sub
List1.Items.RemoveAt(List1.SelectedIndex)
End Sub
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Dim i As Short
Dim s As String
MPlayer1.Visible = False
Slider1.Value = MPlayer1.Volume
For i = 0 To 32000
s = INIReadString("列表框", "歌曲" & i, "", VB6.GetPath & "\song.ini")
If s = "" Then Exit For
List1.Items.Add(s)
Next i
Me.Text = System.Reflection.Assembly.GetExecutingAssembly.GetName.Name
End Sub
#8
接着上楼的!
Private Sub Form1_Closed(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed
Dim i As Short
For i = 0 To List1.Items.Count - 1
Call INIWriteString("列表框", "歌曲" & i, VB6.GetItemString(List1, i), VB6.GetPath & "\song.ini")
Next i
End Sub
Private Sub List1_DoubleClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles List1.DoubleClick
Call Command1_Click(Command1, New System.EventArgs)
End Sub
Private Sub MPlayer1_EndOfStream(ByVal result As Integer)
Dim i As Short
i = List1.SelectedIndex
i = i + 1
If i > List1.Items.Count - 1 Then i = 0
List1.SelectedIndex = i
MPlayer1.FileName = VB6.GetItemString(List1, List1.SelectedIndex)
Call Read_TAG(MPlayer1.FileName, s1, s2, s3, s4, s5, s6) : Call Show_Tag()
Label4.Text = Text1(0).Text
End Sub
Sub Show_Tag()
Text1(0).Text = s1 '歌名
Text1(1).Text = s2 '歌星
Text1(2).Text = s3 '专辑
Text1(3).Text = s4 '出版年
Text1(4).Text = s5 '说明
Text1(5).Text = CStr(s6) '校验码
End Sub
Private Sub Slider1_Scroll(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Slider1.Scroll
MPlayer1.Volume = Slider1.Value - 2500
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
Dim d1, d2 As Short
Dim m1, s1 As Short
Dim m2, s2 As Short
d1 = MPlayer1.CurrentPosition
d2 = MPlayer1.Duration
m1 = d1 \ 60
s1 = d1 Mod 60
m2 = d2 \ 60
s2 = d2 Mod 60
Label3.Text = m1 & ":" & VB6.Format(s1, "00") & " (" & m2 & ":" & VB6.Format(s2, "00") & ")"
End Sub
Private Sub Timer2_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer2.Tick
If VB6.PixelsToTwipsX(Label4.Left) < 0 - VB6.PixelsToTwipsX(Label4.Width) Then
Label4.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Picture1.Width) - 1)
Label4.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Label4.Left) - 5)
Else
Label4.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Label4.Left) - 10)
End If
End Sub
Function Read_TAG(ByRef fname As String, ByRef 歌名 As String, ByRef 歌星 As String, ByRef 专辑名称 As String, ByRef 出版年 As String, ByRef 说明 As String, ByRef 校验码 As Byte)
Dim i As Short, j As Short
Dim k As String
i = FreeFile()
Dim x(127) As Byte
FileOpen(i, fname, OpenMode.Binary, OpenAccess.Read)
'跳到倒数第128位元组
Seek(i, LOF(i) - 127)
'读取127个字符
FileGet(i, x)
'关闭文件
FileClose(i)
If LCase(Chr(x(0)) & Chr(x(1)) & Chr(x(2))) <> "tag" Then
Read_TAG = False
歌名 = ""
歌星 = ""
专辑名称 = ""
出版年 = ""
说明 = ""
校验码 = 0
Exit Function
End If
歌名 = ""
For j = 3 To 32
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
歌名 = 歌名 + k
Next
歌星 = ""
For j = 33 To 62
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
歌星 = 歌星 + k
Next
专辑名称 = ""
For j = 63 To 92
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
专辑名称 = 专辑名称 + k
Next
出版年 = ""
For j = 93 To 96
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
出版年 = 出版年 + k
Next
说明 = ""
For j = 97 To 126
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
说明 = 说明 + k
Next
校验码 = x(127)
Read_TAG = True
End Function
Function INIReadString(ByRef app As String, ByRef keyw As String, ByRef val_Renamed As String, ByRef inifile As String) As String
Dim i As Integer
Dim k As String
k = New String(" ", 255)
i = GetPrivateProfileString(app, keyw, val_Renamed, k, Len(k), inifile)
k = Trim(k) : k = VB.Left(k, Len(k) - 1)
INIReadString = k
End Function
Sub INIWriteString(ByRef app As String, ByRef keyw As String, ByRef val_Renamed As String, ByRef inifile As String)
Dim xx As Short
xx = WritePrivateProfileString(app, keyw, val_Renamed, inifile)
End Sub
Private Sub Form1_Closed(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Closed
Dim i As Short
For i = 0 To List1.Items.Count - 1
Call INIWriteString("列表框", "歌曲" & i, VB6.GetItemString(List1, i), VB6.GetPath & "\song.ini")
Next i
End Sub
Private Sub List1_DoubleClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles List1.DoubleClick
Call Command1_Click(Command1, New System.EventArgs)
End Sub
Private Sub MPlayer1_EndOfStream(ByVal result As Integer)
Dim i As Short
i = List1.SelectedIndex
i = i + 1
If i > List1.Items.Count - 1 Then i = 0
List1.SelectedIndex = i
MPlayer1.FileName = VB6.GetItemString(List1, List1.SelectedIndex)
Call Read_TAG(MPlayer1.FileName, s1, s2, s3, s4, s5, s6) : Call Show_Tag()
Label4.Text = Text1(0).Text
End Sub
Sub Show_Tag()
Text1(0).Text = s1 '歌名
Text1(1).Text = s2 '歌星
Text1(2).Text = s3 '专辑
Text1(3).Text = s4 '出版年
Text1(4).Text = s5 '说明
Text1(5).Text = CStr(s6) '校验码
End Sub
Private Sub Slider1_Scroll(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Slider1.Scroll
MPlayer1.Volume = Slider1.Value - 2500
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
Dim d1, d2 As Short
Dim m1, s1 As Short
Dim m2, s2 As Short
d1 = MPlayer1.CurrentPosition
d2 = MPlayer1.Duration
m1 = d1 \ 60
s1 = d1 Mod 60
m2 = d2 \ 60
s2 = d2 Mod 60
Label3.Text = m1 & ":" & VB6.Format(s1, "00") & " (" & m2 & ":" & VB6.Format(s2, "00") & ")"
End Sub
Private Sub Timer2_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer2.Tick
If VB6.PixelsToTwipsX(Label4.Left) < 0 - VB6.PixelsToTwipsX(Label4.Width) Then
Label4.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Picture1.Width) - 1)
Label4.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Label4.Left) - 5)
Else
Label4.Left = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Label4.Left) - 10)
End If
End Sub
Function Read_TAG(ByRef fname As String, ByRef 歌名 As String, ByRef 歌星 As String, ByRef 专辑名称 As String, ByRef 出版年 As String, ByRef 说明 As String, ByRef 校验码 As Byte)
Dim i As Short, j As Short
Dim k As String
i = FreeFile()
Dim x(127) As Byte
FileOpen(i, fname, OpenMode.Binary, OpenAccess.Read)
'跳到倒数第128位元组
Seek(i, LOF(i) - 127)
'读取127个字符
FileGet(i, x)
'关闭文件
FileClose(i)
If LCase(Chr(x(0)) & Chr(x(1)) & Chr(x(2))) <> "tag" Then
Read_TAG = False
歌名 = ""
歌星 = ""
专辑名称 = ""
出版年 = ""
说明 = ""
校验码 = 0
Exit Function
End If
歌名 = ""
For j = 3 To 32
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
歌名 = 歌名 + k
Next
歌星 = ""
For j = 33 To 62
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
歌星 = 歌星 + k
Next
专辑名称 = ""
For j = 63 To 92
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
专辑名称 = 专辑名称 + k
Next
出版年 = ""
For j = 93 To 96
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
出版年 = 出版年 + k
Next
说明 = ""
For j = 97 To 126
If x(j) < 128 Then k = Chr(x(j)) Else k = Chr("&H" + Hex(x(j)) + Hex(x(j + 1))) : j = j + 1
说明 = 说明 + k
Next
校验码 = x(127)
Read_TAG = True
End Function
Function INIReadString(ByRef app As String, ByRef keyw As String, ByRef val_Renamed As String, ByRef inifile As String) As String
Dim i As Integer
Dim k As String
k = New String(" ", 255)
i = GetPrivateProfileString(app, keyw, val_Renamed, k, Len(k), inifile)
k = Trim(k) : k = VB.Left(k, Len(k) - 1)
INIReadString = k
End Function
Sub INIWriteString(ByRef app As String, ByRef keyw As String, ByRef val_Renamed As String, ByRef inifile As String)
Dim xx As Short
xx = WritePrivateProfileString(app, keyw, val_Renamed, inifile)
End Sub
#9
这是之前的相关声明
Option Strict Off
Option Explicit On
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.IO
Imports VB = Microsoft.VisualBasic
楼主如果还看不明白!我的电子邮件是SNRMNM_SX@163.COM
Option Strict Off
Option Explicit On
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.IO
Imports VB = Microsoft.VisualBasic
楼主如果还看不明白!我的电子邮件是SNRMNM_SX@163.COM
#10
牛的!