自学内容网 自学内容网

VB6.0桌面小程序(桌面音乐播放器)

干货源码

Imports System.IO
Imports System.Security.Cryptography

Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Button1.Text = “上一曲”
Button4.Text = “播放”
Button3.Text = “下一曲”
Button2.Text = “顺序播放”
Button7.Text = “打开文件”
Button6.Text = “打开目录”
Button9.Text = “本地视频”
Button8.Text = “网络视频”
Button5.Text = “搜索歌曲”
Label1.Text = “00:00”
Label2.Text = “00:00”
Label3.Text = “歌词显示”
Label4.Text = “未播放”
Label5.Text = “正在播放:”
Label6.Text = “20%”
End Sub
Dim files(), paths()
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
OpenFileDialog1.Filter = “选择音频|.mp3;.flac;.wav;.mp4”
OpenFileDialog1.Multiselect = True
If OpenFileDialog1.ShowDialog = DialogResult.OK Then

        localSelectPathList.Clear()
        ListBox1.Items.Clear()
        If files Is Nothing Then
        Else
            Array.Clear(files)
        End If

        If paths Is Nothing Then
        Else
            Array.Clear(paths)
        End If


        files = OpenFileDialog1.FileNames
        paths = OpenFileDialog1.FileNames
        For Each file In files
            ListBox1.Items.Add(file)
        Next file
    End If

End Sub
Dim localSelectPath As String
Dim localSelectPathList As New List(Of String)
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
    If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then

        localSelectPath = FolderBrowserDialog1.SelectedPath
        For Each path In Directory.GetFiles(localSelectPath)
            localSelectPathList.Add(path)
            ListBox1.Items.Add(path)
        Next path
    End If
End Sub

Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
    If localSelectPathList.Count > 0 Then
        AxWindowsMediaPlayer1.URL = localSelectPathList.Item(ListBox1.SelectedIndex)
        AxWindowsMediaPlayer1.Ctlcontrols.play()
    Else
        AxWindowsMediaPlayer1.URL = paths.GetValue(ListBox1.SelectedIndex)
        AxWindowsMediaPlayer1.Ctlcontrols.play()
    End If
    Button4.Text = "暂停"

End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    If Button4.Text Is "暂停" Then
        Button4.Text = "播放"
        AxWindowsMediaPlayer1.Ctlcontrols.pause()
    Else
        Button4.Text = "暂停"
        AxWindowsMediaPlayer1.Ctlcontrols.play()

    End If

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If ListBox1.Items Is Nothing Then
        Return
    End If
    If ListBox1.SelectedIndex = 0 Then
        ListBox1.SelectedIndex = ListBox1.Items.Count - 1
    Else
        ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1
    End If
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    If ListBox1.Items Is Nothing Then
        Return
    End If
    If ListBox1.SelectedIndex = ListBox1.Items.Count - 1 Then
        ListBox1.SelectedIndex = 0
    Else
        ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
    End If
End Sub

End Class

图形界面设计

在这里插入图片描述

运行后效果截图

在这里插入图片描述

功能总结

项目已经实现程序相关功能,本项目中播放器通过导入微软自带控件实现。判断写法略麻烦,不如C#,java等面向对象语言语法清晰简洁。


原文地址:https://blog.csdn.net/weixin_37691186/article/details/143582706

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!