接着上楼的!
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
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 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