Results 1 to 23 of 23

Thread: [RESOLVED] Play audio

Hybrid View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    18

    Resolved [RESOLVED] Play audio

    Hello im some what new with vb Im wondering how to create a just a Play and stop button and when u click play it will connect to a site like shout cast url or a listen live radio url thanks.

    If tried a sorce code example

    "
    Private Sub Form_Load()
    psSoundFile = AppPath & "http://example.com/live.wav"
    If Dir(psSoundFile) = "" Then
    MsgBox "Sample .wav file not found; can't run", , "Error"
    Else
    MMControl1.DeviceType = "WAVEAUDIO"
    MMControl1.FileName = psSoundFile
    StopWav
    End If
    End Sub
    "

    and when i click play it says wav file not found etc.
    Last edited by dcool96; Feb 8th, 2007 at 01:47 AM.

  2. #2
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Play audio

    Welcome to the forums


    You will need to download the file first before playing it. MMControl can only open files that are on the computer. You can try searching the forum for examples.

    Edit: Http://www.vbforums.com/showthread.p...t=play+wav+url
    Last edited by Andrew G; Feb 7th, 2007 at 12:26 AM.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    18

    Re: Play audio

    Im not sure i guess like you said you cannot play audio threw that type of fuction do you know any other codes you can use to play audio from a url?

  4. #4
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Play audio

    dcool the best way would be doing it like Andrew proposed. Download it first then play it.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    18

    Re: Play audio

    well what i was going to do is create a simple program that all you have to do is open it click play it would connect to a url to on a radio site its simple to connect i have the url but i want it in a program format so i dont have to open html every time i want to start to listen plus it will be cleaner etc and alot of users already said they would use it becuase on the radio site it has annyoing ads etc
    Last edited by dcool96; Feb 8th, 2007 at 12:50 AM.

  6. #6
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Play audio

    Have you started this project at all? Like setup the GUI?

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    18

    Re: Play audio

    Ive messed around with codes but havnt started yet till i fiqure out how to get it to play :/

  8. #8
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Play audio

    Hmm i unsure how to go about this but maybe it is possible to connect to this site then play the songs through your program.

  9. #9
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Play audio

    o btw can you give me the URL link so i can see what i can find out.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    18

    Re: Play audio

    umm its php http://www.933flz.com/cc-common/stre...new/genasx.php if the the script only reads like .wav .mp3 or w/e i can redirect it to the php with .wav ext or w/e

  11. #11
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Play audio

    You will need to use the Windows Media Player control almost definitely.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    18

    Re: Play audio

    I found a better url http://mfile.akamai.com/19869/live/r...ION_ID=WFLZ-FM

    how do you add windows media control to the form? do you have any examples?


    Thanks

  13. #13
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Play audio

    Press Ctrl + T
    and then check the check box near Windows Media Player

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    18

    Re: Play audio

    Ok where getting some where now i added media player

    Private Sub WindowsMediaPlayer1_OpenStateChange(ByVal NewState As Long)

    End Sub

    how do I enter the url into that?

  15. #15
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Play audio

    Well i haven't done alot at all with the WMP control or done anything like what you are attempting.

    Anyway i think you need the inet control as well because WMP does not have a connect routine.

  16. #16
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Play audio

    If you wish to stream large data without the use of WMP, then i think your going to have to download a small section, then play it and as your playing, you download a new section and so forth. This is something quick if its only a small file, as it downloads it all, but you can make it download chunks at a time as well.

    All it needs is the Internet Transfer Control. It will download the file (without saving it) and play it from memory.
    VB Code:
    1. #If Win32 Then
    2.     Private Declare Function sndPlaySound Lib "WINMM.DLL" Alias "sndPlaySoundA" _
    3.         (ByVal lpszSoundName As Any, ByVal uFlags As Long) As Long
    4. #Else
    5.     Private Declare Function sndPlaySound Lib "MMSYSTEM.DLL" _
    6.         (ByVal lpszSoundName As Any, ByVal wFlags As Integer) As Integer
    7. #End If
    8.  
    9. Const SND_ASYNC = &H1     ' Play asynchronously
    10. Const SND_NODEFAULT = &H2 ' Don't use default sound
    11. Const SND_MEMORY = &H4    ' lpszSoundName points to a memory file
    12.  
    13. Private Sub Command1_Click()
    14. Dim ret() As String
    15. Dim StrHeader As String
    16. Dim FileLength As Long
    17. Dim FileB() As Byte
    18.    
    19.     Inet1.URL = "http://www.wav-sounds.com/cartoon/daffyduck1.wav"
    20.     Inet1.Execute , "GET", , "Range: bytes=" & CStr(0) & "-" & vbCrLf
    21.        
    22.     Do While Inet1.StillExecuting
    23.     DoEvents
    24.     Loop
    25.  
    26.     StrHeader = Inet1.GetHeader("Content-Range")
    27.     If InStr(1, StrHeader, "/") Then
    28.         ret = Split(StrHeader, "/")
    29.         FileLength = CLng(ret(1))
    30.     End If
    31.    
    32.     FileB = Inet1.GetChunk(FileLength, icByteArray)
    33.  
    34.  
    35.     Dim SndRet As Long
    36.     Dim soundbuffer As String
    37.     #If Win32 Then
    38.         ' Important: The returned string is converted to Unicode
    39.         soundbuffer = StrConv(FileB, vbUnicode)
    40.     #Else
    41.         soundbuffer = LoadResData(FileB, "Sounds")
    42.     #End If
    43.     SndRet = sndPlaySound(soundbuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY)
    44.     ' Important: This function is neccessary for playing sound asynchronously
    45.     DoEvents
    46. End Sub

  17. #17
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Play audio

    Windows Media Player supports seamless audio streaming. I've rarely used it but it should have a URL property.

    Mess around with the properties/methods until you find something.

    WindowsMedia1.URL
    WindowsMedia1.Play (URL)

    Look at what items pop up in intellisense and try to figure it out. That's one reason intellisense is there.

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    18

    Re: Play audio

    ive tried both codes the long one im still studing the long code but i tried

    [CODE]Private Sub WindowsMediaPlayer1_OpenStateChange(ByVal NewState As Long)
    WindowsMedia1.URL
    WindowsMedia1.play (www.example.com/live.wav)
    End SubCODE]

    and the WMP just sits there does nothing im probley missing something

  19. #19
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Play audio

    Use Andrew G's method method. Place it in a command button click event or something.

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Feb 2007
    Posts
    18

    Re: Play audio

    the last code u gave me

    Private Sub Form_Load()
    WindowsMediaPlayer1.URL = "http://example.com/live.wav"
    WindowsMediaPlayer1.Controls.play
    End Sub

    works thanks every one and andrew!

  21. #21
    Junior Member
    Join Date
    Aug 2006
    Posts
    25

    Re: Play audio

    Quote Originally Posted by Andrew G
    If you wish to stream large data without the use of WMP, then i think your going to have to download a small section, then play it and as your playing, you download a new section and so forth. This is something quick if its only a small file, as it downloads it all, but you can make it download chunks at a time as well.

    All it needs is the Internet Transfer Control. It will download the file (without saving it) and play it from memory.
    VB Code:
    1. #If Win32 Then
    2.     Private Declare Function sndPlaySound Lib "WINMM.DLL" Alias "sndPlaySoundA" _
    3.         (ByVal lpszSoundName As Any, ByVal uFlags As Long) As Long
    4. #Else
    5.     Private Declare Function sndPlaySound Lib "MMSYSTEM.DLL" _
    6.         (ByVal lpszSoundName As Any, ByVal wFlags As Integer) As Integer
    7. #End If
    8.  
    9. Const SND_ASYNC = &H1     ' Play asynchronously
    10. Const SND_NODEFAULT = &H2 ' Don't use default sound
    11. Const SND_MEMORY = &H4    ' lpszSoundName points to a memory file
    12.  
    13. Private Sub Command1_Click()
    14. Dim ret() As String
    15. Dim StrHeader As String
    16. Dim FileLength As Long
    17. Dim FileB() As Byte
    18.    
    19.     Inet1.URL = "http://www.wav-sounds.com/cartoon/daffyduck1.wav"
    20.     Inet1.Execute , "GET", , "Range: bytes=" & CStr(0) & "-" & vbCrLf
    21.        
    22.     Do While Inet1.StillExecuting
    23.     DoEvents
    24.     Loop
    25.  
    26.     StrHeader = Inet1.GetHeader("Content-Range")
    27.     If InStr(1, StrHeader, "/") Then
    28.         ret = Split(StrHeader, "/")
    29.         FileLength = CLng(ret(1))
    30.     End If
    31.    
    32.     FileB = Inet1.GetChunk(FileLength, icByteArray)
    33.  
    34.  
    35.     Dim SndRet As Long
    36.     Dim soundbuffer As String
    37.     #If Win32 Then
    38.         ' Important: The returned string is converted to Unicode
    39.         soundbuffer = StrConv(FileB, vbUnicode)
    40.     #Else
    41.         soundbuffer = LoadResData(FileB, "Sounds")
    42.     #End If
    43.     SndRet = sndPlaySound(soundbuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY)
    44.     ' Important: This function is neccessary for playing sound asynchronously
    45.     DoEvents
    46. End Sub
    I am trying to accomplish something like this but how can i make it play .mp3 instead of .wav as the "sndPlaySound" declaration can only play .wav

    any help will be appreciated.

  22. #22
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Play audio

    Using WMP 10.
    VB Code:
    1. Private Sub Form_Load()
    2.     WindowsMediaPlayer1.URL = "http://www.wav-sounds.com/cartoon/daffyduck1.wav"
    3.     WindowsMediaPlayer1.Controls.play
    4. End Sub

    Edit: added the version i have incase.
    Last edited by Andrew G; Feb 8th, 2007 at 01:37 AM.

  23. #23
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: Play audio

    hmmm my version of the ocx must be older

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