我目前正在开展一个项目以及我需要在程序后台添加音乐的其中一个因素。除音乐不播放外,一切正常。
我添加了命令My.Computer.Audio.Play(“Path of File”,AudioPlayMode.WaitToComplete“)
我也尝试过将.wav / .mp3添加到项目资源然后使用My.Computer.Audio.Play(My.Resources.musicfile,AudioPlayMode.WaitToComplete“)
的变体。最后,这些两者都不起作用?是否有另一种方法将音乐添加到我的Visual Basic程序。 (我在Microsoft Visual Studio中使用Visual Basics表单。)
答案 0 :(得分:1)
据我所知,My.Computer.Audio.Play("Path of File", AudioPlayMode.WaitToComplete")
不允许您播放除 .wav
您可以使用提供的MediaPlayer
播放 .mp3
现在编码部分:
您需要导入WMPLib
添加以下行:
Imports WMPLib
然后是form_load
'add a media player
Dim Player As WindowsMediaPlayer = New WindowsMediaPlayer
'assign the location of the song to be played
Dim SongLocation = "D:\Music\Single\Skrillex 2 Hours HQ Longest On Youtube).mp3" 'any song you want to play
'play the song
Player.URL = SongLocation
Player.controls.play()
就是这样,当你加载表单时,歌曲会自动播放。希望它能帮到你:)。
<小时/> 的修改 请按照以下步骤操作:
F:\ Visual Studios 2010 \ Projects \ stackoverflow \ stackoverflow \ bin \ Debug
现在将您的代码更改为:
Imports System.IO
Imports WMPLib
Public Class Launcher
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim Player As WindowsMediaPlayer = New WindowsMediaPlayer
Dim SongLocation = Path.Combine(Application.StartupPath,"mmusic.mp3")
Player.URL = SongLocation
Player.controls.play()
End Sub
End Class