|
-
Feb 6th, 2007, 11:48 PM
#1
Thread Starter
Junior Member
[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.
-
Feb 7th, 2007, 12:15 AM
#2
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.
-
Feb 8th, 2007, 12:38 AM
#3
Thread Starter
Junior Member
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?
-
Feb 8th, 2007, 12:42 AM
#4
Re: Play audio
dcool the best way would be doing it like Andrew proposed. Download it first then play it.
-
Feb 8th, 2007, 12:46 AM
#5
Thread Starter
Junior Member
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.
-
Feb 8th, 2007, 12:48 AM
#6
Re: Play audio
Have you started this project at all? Like setup the GUI?
-
Feb 8th, 2007, 12:49 AM
#7
Thread Starter
Junior Member
Re: Play audio
Ive messed around with codes but havnt started yet till i fiqure out how to get it to play :/
-
Feb 8th, 2007, 12:53 AM
#8
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.
-
Feb 8th, 2007, 12:54 AM
#9
Re: Play audio
o btw can you give me the URL link so i can see what i can find out.
-
Feb 8th, 2007, 12:55 AM
#10
Thread Starter
Junior Member
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
-
Feb 8th, 2007, 01:01 AM
#11
Re: Play audio
You will need to use the Windows Media Player control almost definitely.
-
Feb 8th, 2007, 01:03 AM
#12
Thread Starter
Junior Member
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
-
Feb 8th, 2007, 01:06 AM
#13
Re: Play audio
Press Ctrl + T
and then check the check box near Windows Media Player
-
Feb 8th, 2007, 01:08 AM
#14
Thread Starter
Junior Member
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?
-
Feb 8th, 2007, 01:22 AM
#15
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.
-
Feb 8th, 2007, 01:23 AM
#16
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:
#If Win32 Then
Private Declare Function sndPlaySound Lib "WINMM.DLL" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As Any, ByVal uFlags As Long) As Long
#Else
Private Declare Function sndPlaySound Lib "MMSYSTEM.DLL" _
(ByVal lpszSoundName As Any, ByVal wFlags As Integer) As Integer
#End If
Const SND_ASYNC = &H1 ' Play asynchronously
Const SND_NODEFAULT = &H2 ' Don't use default sound
Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
Private Sub Command1_Click()
Dim ret() As String
Dim StrHeader As String
Dim FileLength As Long
Dim FileB() As Byte
Inet1.URL = "http://www.wav-sounds.com/cartoon/daffyduck1.wav"
Inet1.Execute , "GET", , "Range: bytes=" & CStr(0) & "-" & vbCrLf
Do While Inet1.StillExecuting
DoEvents
Loop
StrHeader = Inet1.GetHeader("Content-Range")
If InStr(1, StrHeader, "/") Then
ret = Split(StrHeader, "/")
FileLength = CLng(ret(1))
End If
FileB = Inet1.GetChunk(FileLength, icByteArray)
Dim SndRet As Long
Dim soundbuffer As String
#If Win32 Then
' Important: The returned string is converted to Unicode
soundbuffer = StrConv(FileB, vbUnicode)
#Else
soundbuffer = LoadResData(FileB, "Sounds")
#End If
SndRet = sndPlaySound(soundbuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY)
' Important: This function is neccessary for playing sound asynchronously
DoEvents
End Sub
-
Feb 8th, 2007, 01:29 AM
#17
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.
-
Feb 8th, 2007, 01:41 AM
#18
Thread Starter
Junior Member
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
-
Feb 8th, 2007, 01:43 AM
#19
Re: Play audio
Use Andrew G's method method. Place it in a command button click event or something.
-
Feb 8th, 2007, 01:46 AM
#20
Thread Starter
Junior Member
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!
-
Apr 20th, 2007, 03:40 PM
#21
Junior Member
Re: Play audio
 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:
#If Win32 Then
Private Declare Function sndPlaySound Lib "WINMM.DLL" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As Any, ByVal uFlags As Long) As Long
#Else
Private Declare Function sndPlaySound Lib "MMSYSTEM.DLL" _
(ByVal lpszSoundName As Any, ByVal wFlags As Integer) As Integer
#End If
Const SND_ASYNC = &H1 ' Play asynchronously
Const SND_NODEFAULT = &H2 ' Don't use default sound
Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
Private Sub Command1_Click()
Dim ret() As String
Dim StrHeader As String
Dim FileLength As Long
Dim FileB() As Byte
Inet1.URL = "http://www.wav-sounds.com/cartoon/daffyduck1.wav"
Inet1.Execute , "GET", , "Range: bytes=" & CStr(0) & "-" & vbCrLf
Do While Inet1.StillExecuting
DoEvents
Loop
StrHeader = Inet1.GetHeader("Content-Range")
If InStr(1, StrHeader, "/") Then
ret = Split(StrHeader, "/")
FileLength = CLng(ret(1))
End If
FileB = Inet1.GetChunk(FileLength, icByteArray)
Dim SndRet As Long
Dim soundbuffer As String
#If Win32 Then
' Important: The returned string is converted to Unicode
soundbuffer = StrConv(FileB, vbUnicode)
#Else
soundbuffer = LoadResData(FileB, "Sounds")
#End If
SndRet = sndPlaySound(soundbuffer, SND_ASYNC Or SND_NODEFAULT Or SND_MEMORY)
' Important: This function is neccessary for playing sound asynchronously
DoEvents
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.
-
Feb 8th, 2007, 01:33 AM
#22
Re: Play audio
Using WMP 10.
VB Code:
Private Sub Form_Load()
WindowsMediaPlayer1.URL = "http://www.wav-sounds.com/cartoon/daffyduck1.wav"
WindowsMediaPlayer1.Controls.play
End Sub
Edit: added the version i have incase.
Last edited by Andrew G; Feb 8th, 2007 at 01:37 AM.
-
Feb 8th, 2007, 01:33 AM
#23
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|