How to Pan the Audio in an FLVPlayback Video
This one came to me in a flash (ha ha … Flash!), thanks to a friendly discussion I had the other day with site visitor Michael Lokner. He was wondering if it was possible to pan the audio portion of an FLV file in cases where the video is played in an instance of the FLVPlayback Component. In another recent article, I explained how to use the MovieClip.attachAudio() method to control NetStream-based video, but that’s a different ball of wax. The FLVPlayback Component has its own volume property, and even skins that feature a volume slider, but what about panning? After bouncing ideas back and forth, Michael and I arrived at a simple answer.
An answer, short and sweet
On his own, Michael had arrived at a respectable workaround, which was to create a Sound instance associated with the main timeline (accomplished by omitting any movie clip reference when constructing the instance). By setting up the Sound instance to control the whole movie, any panning would naturally affect the video’s audio track. The only shortcoming is that the panning would also affect all other audio in the movie. How to associate this panning with the FLVPlayback instance only?
The answer turned out to be effortless. As it turns out, all ActionScript 2.0 Components, if they have a UI, are ultimately instances of the MovieClip class. Look up any one of them in the Components Language Reference and you’ll see that it extends MovieClip. What this means, of course, is that you can use the FLVPlayback Component itself as the parameter when creating a Sound instance. Assuming an FLVPlayback instance name of videoPlayer:
var videoSound:Sound = new Sound(videoPlayer);
videoSound.setPan(-100) // hard left
videoSound.setPan(100) // hard right
How it works
Even though Components are very sophisticated objects, with lengthy inheritance chains, in the end, they are what they are: movie clips. Sound objects associated with a movie clip control that movie clip’s audio.
May 2nd, 2007 at 9:42 pm
Wow, thanks again!
Especially for the (?:) advertisement, I’ve been pining for an operator like this for ages
May 2nd, 2007 at 9:43 pm
^Haha, just realized this was wrong article. My praises still stand, however.
May 2nd, 2007 at 10:17 pm
Kyoji,
lol … thanks!
August 24th, 2007 at 11:14 am
Hi David,
have u ever used the .load() mthod for the videoplayer class?
I try using it but the video will not load. Yet if I just do ns.play() etc and supply a value in the () video loads and plays… do u know why?
I want to load it but not play it, in other words, i want to see the video there…but not have it play. The online documentation says this .load method will load but not play it.
KInd regards, John
August 27th, 2007 at 7:18 pm
john,
Have you checked out the extensive (112 page)
VideoPlayerAPI at the old Macromedia site? The hyperlink still works. It’s a PDF file that amounts to the “missing manual” for this class. Let me know if this helps you out. I mentioned it in an earlier blog entry here:http://www.quip.net/blog/2007/flash/actionscript-20/videoplayer-class-api
November 1st, 2007 at 10:38 am
David,
We have been using wmv format training videos for several years with two language tracks (Spanish & English). We only need one video file, and the user can switch the language on the fly. The media files are stored locally on a kiosk, so bandwidth isn’t an issue at this time. However, we are working toward going to a web delivery system and are experimenting with flv. Have you ever heard of a way to set up flv files this way? Or do you have to encode separate flv files for each language, or leave the audio out of the flv and play separate mp3s?
Denise
November 1st, 2007 at 2:21 pm
Denise,
I’ve not seen a way to encode more than one audio or video stream per FLV file — not with the native Flash Video Encoder, Sorenson Squeeze, or On2 Flix Pro — but that doesn’t mean the endeavor is necessarily impossible … only that I don’t know for sure either way.
I do know that Flash Media Server is capable of distributing multiple content streams based on bandwidth, so that would be my first avenue of inquiry. Be aware, however, that Flash Media Server is a relatively expensive product. If FMS was out of my project’s budget, I would first experiment with a single video-only FLV and pair of MP3s (just to save on bandwidth) but would settle for two FLVs if synching became problematic.
November 2nd, 2007 at 12:30 pm
Thanks for the feedback. I’ll do some research on the Flash Media Server.
November 3rd, 2007 at 10:52 am
Denise,
Sure thing. Best of luck with that!