Microsoft 开发人员网络 > 论坛主页 > Visual Basic General > Visual basic 2005 sound midi mp3 or wav files?
提出问题提出问题
 

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

  • 2008年6月23日 19: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

全部回复