How do I record sound using a microphone and then send it to the server?
I find it interesting sometimes that this type of question still comes through. It means two things to me. One is that Adobe lacks easily accessible information and examples on FMS, or I suppose at the very least the information isn't in obvious spots. Two, there are still new people coming to FMS., which is always good of course.
The question: How do I record sound using a microphone and then send it to the server?
This isn't so tough, but my concern with the wording of this question is that the user thinks that perhaps it's possible to record the microphone client side and then save it on the server.
If by chance that is the case, then it isn't really possible. The best you can do in that area with just flash is to buffer a lot and then have the flash player "upload" it to the server. But in reality, it's not saving it anywhere in hard memory and is deleted if you close the flash player. The reason you might want to do something like this is if you are concerned that the user's bandwidth is much lower than they may need to stream the audio up to the server. So you buffer it on the client side (usually if it's under 30 seconds of audio you should be ok) and then flush the buffer when it reaches the limit.
So, how about some code then:
I won't cover making a net connection to the server and all that because I've talked about that in the past and there really are lots of examples of it (every FMS app needs to connect to the server..)
Once a connection has been made to the server, let's call a function called getMic()
Assuming the netConnection object is "nc", netstream to publish the mic is "ns" and the microphone object is "mic"
//this function will get the microphone object and set some parameters for it
//first we need a netstream object to connect the mic to
ns = new NetStream(nc);
//set a small buffer
//we need the microphone object now, get the default mic by passing in nothing in the parantheses
mic = Microphone.get();
//set the quality of the microphone, this can be set to 5, 8, 11, 22, or 44
//attach the microphone object to the netstream
//and publish it to the server by passing in the file name and record command. If you want a live stream, then just pass in "LIVE" instead of "RECORD"
and that's it really. There are a few other options for the microphone which can be seen here on the livedocs for FMS.
Posted by: Graeme Bull on Apr 05, 2007
Share This Article
Willow | Wowza Media Server Management made easy
Willow is the answer to any Wowza Media Server developer's or administrator's problem of how to see what your Wowza Media Server is doing at any one time.We created Willow to meet our needs to be able to see what is going with our applications and servers publishing and playing all types of streams and shared objects.