MSDN > 論壇首頁 > Visual Basic General > Visual basic 2005 sound midi mp3 or wav files?
發問發問
 

已答覆Visual basic 2005 sound midi mp3 or wav files?

  • 2008年6月23日 下午 07:17turkeygizzard 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    How would I incorporate sound into a program? For instance a starting form then within the body of the program? Would I need to use a timer or is a midi file usable as it is? 

解答

  • 2008年6月28日 上午 10:07John Anthony Oliver 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆包含代碼
    Hi,

    This is how to play WAVE *.wav files.

    Choose between;

    My.Computer.Audio.Play(ofd.FileName, AudioPlayMode.Background)

    or

    My.Computer.Audio.Play(ofd.FileName, AudioPlayMode.BackgroundLoop)

    or

    My.Computer.Audio.Play(ofd.FileName, AudioPlayMode.WaitToComplete)


    This works with Windows XP. :-) ;-)

    I'm not sure if VISTA still has a media folder containing WAVE files.

    Add 1 button to a FORM to try this code please.

    ofd.FileName here is the full path and filename returned from the OpenFileDialog.







    Option Strict On

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim ofd As New OpenFileDialog
    ofd.InitialDirectory = "C:\Windows\media"
    ofd.Filter = "Wave files only|*.wav"
    Try
    ofd.ShowDialog()

    My.Computer.Audio.Play(ofd.FileName, AudioPlayMode.Background)

    Catch ex As Exception
    MessageBox.Show(ex.ToString)
    End Try

    End Sub
    End Class





    Regards,

    John

所有回覆