MSDN > Home page del forum > Visual Basic General > Visual basic 2005 sound midi mp3 or wav files?
Formula una domandaFormula una domanda
 

Con rispostaVisual basic 2005 sound midi mp3 or wav files?

  • lunedì 23 giugno 2008 19.17turkeygizzard Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     
    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? 

Risposte

  • sabato 28 giugno 2008 10.07John Anthony Oliver Medaglie utenteMedaglie utenteMedaglie utenteMedaglie utenteMedaglie utente
     Con rispostaContiene codice
    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

Tutte le risposte