Results 1 to 12 of 12

Thread: Playing Music

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Question Playing Music

    How Can I Play Music Just Normal MP3 Music Without Using
    Windows Media Player.

    Thnx In Advance

  2. #2
    Addicted Member
    Join Date
    Jul 2006
    Location
    Adelaide, Australia
    Posts
    204

    Re: Playing Music

    you could use the Windows Media Player control, and set visible to false

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Playing Music

    See our Classic VB FAQs (in the FAQ forum, or via the link in my signature) for examples of a few methods.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Re: Playing Music

    Aah Ok Thnx

  5. #5
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: Playing Music

    Two ways that you might find helpful are the sndPlaySound API and the MMControl that can be added in VB.

    sndPlaySound

    This function plays the sound specified by 'lpszPlaySound' parameter. This function is limited to .wav files. An example of use is shown below.

    VB Code:
    1. Option Explicit
    2.  
    3. ' Plays the sound specified by
    4. ' lpszPlaySound. This function is
    5. ' limited to .wav files.
    6. Private Declare Function sndPlaySound _
    7.     Lib "winmm.dll" _
    8.     Alias "sndPlaySoundA" ( _
    9.         ByVal lpszSoundName As String, _
    10.         ByVal uFlags As Long) _
    11.         As Long
    12.        
    13. Private Const SND_NOWAIT    As Long = &H2000                    ' Don't wait if the driver is busy
    14. Private Const SND_SYNC      As Long = &H0                       ' Play synchronously (default)
    15. Private Const SND_FLAGS     As Long = SND_SYNC Or SND_NOWAIT    ' Combination of two constants above
    16.  
    17. Private Sub Command1_Click()
    18.     ' Call sndPlaySound to play our file
    19.     Call sndPlaySound(App.Path & "\Chimes.wav", SND_FLAGS)
    20. End Sub

    MMControl

    This is a control that can be added through Visual Basic 6.0 by going to Project > Components and selecting 'Microsoft Multimedia Control 6.0'. This control can play a mixture of sound types and is of more use than sndPlaySound if you are playing music through VB. An example on using this is below:

    VB Code:
    1. Private Sub Form_Load()
    2.     With MMControl1
    3.         .FileName = App.Path & "\Sound.wma"     ' Set the file to be played
    4.         .Command = "Open"                       ' Open the file
    5.         .Command = "Play"                       ' Play the file
    6.     End With
    7. End Sub

    Hope this is of some help

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Playing Music

    I hope you don't mind Jenova, but I copied your post to the FAQ thread (as your methods weren't in it already).

  7. #7
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: Playing Music

    No that's fine . Thanks a lot

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Re: Playing Music

    Aah This Is What I Searched For
    Yhnnxx Man Reaaly Thnx

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Re: Playing Music

    No Errors, But It Doesnt Play The Music
    Does It Only Works For .Wav Sounds
    Cuz I Wanted To Play .MP3 Files

    VB Code Code:
    1. Call sndPlaySound("C:\Documents and Settings\Administrator\My Documents\My Music\Other\Wai A Pasi.mp3", SND_FLAGS)

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Playing Music

    Quote Originally Posted by XCustoms
    Does It Only Works For .Wav Sounds
    Yes:
    Quote Originally Posted by Jenova
    sndPlaySound
    .. This function is limited to .wav files.
    Try a different method.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    65

    Re: Playing Music

    MP3 File Worked But Only With MMControl But Not Normal
    I Want To Create My Own Button

  12. #12
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    Re: Playing Music

    When you say Create your own button can you be more specific? Do you mean you want to press a button and play the file? If that is the case you just need to use the code that i showed you before in a button click event.

    VB Code:
    1. Private Sub Command1_Click()    
    2.     With MMControl1        
    3.         .FileName = App.Path & "\Sound.wma"     ' Set the file to be played  
    4.         .Command = "Open"                             ' Open the file        
    5.         .Command = "Play"                              ' Play the file    
    6.     End With
    7. End Sub

    Hope this helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width