Question

How to embed Flash video player with sound muted by default and loop

Asked by: betagirl

Hi Experts -

I am embedding a short video on a web page. The video needs to loop, and I'd like it to be muted by default - with only the mute control button available so the user can un-mute and hear the sound if desired.

I'm using Flash CS3 - AS 3.0 - the standard MuteButton component, an external .flv file.  

The only solution I've been able to come up with is to include a VolumeBar and set it to 0 . I don't want this UI however.  I'm pretty sure there's gotta be a way to do what I need to do, but I'm nowhere near being a Flash expert so any specific tips/code/etc. would be great.

Also, I'd like the video to loop - and have set this in the publish settings as well as the params in the html - yet it's not looping. How to control looping? Thanks!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-01-20 at 19:41:55ID23097405
Tags

Flash CS3

Topic

Adobe Flash

Participating Experts
2
Points
0
Comments
24

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Keyboard button to mute Media Player
    Is there a way to program the keyboard so as to make one of the buttons mute and unmute the Media Player? I have people come into my office and would like to be able to mute without having to find the Media Player Window and pushing the mute button. My boss's new keyboard h...
  2. sound on/mute button on FLV
    HI, I am streaming an flv through the following code: // var connection_nc:NetConnection = new NetConnection(); connection_nc.connect(null); var stream_ns:NetStream = new NetStream(connection_nc); vidTV.attachVideo(stream_ns); stream_ns.play("video.flv"); // the ...
  3. Mute Button embedded loop Video
    Hi Experts, i have an embedded video. I need a mute button (default sound volume 0). The vid should loop. The final file should be a swf (embedded vid) not a swf with flv. How to? Thanks! GT
  4. Mute sounds in a swf at the time of embedding.???
    Hi all. I have a SWF movie which plays background mucis. I need to embed this SWF into a page, with full functionality. But i need it to be silent / muted. I do not have acces to the original flash file, so i cant see any parameters inside etc.. There should be no other sound...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: tagitPosted on 2008-01-20 at 19:53:22ID: 20703731

Here is an example from the language reference, note you could add the followiing function

function muteSound() {
    audio_sound.setVolume(0);
}

var my_nc:NetConnection = new NetConnection();
my_nc.connect(null);
var my_ns:NetStream = new NetStream(my_nc);
my_video.attachVideo(my_ns);
my_ns.play("yourVideo.flv");
this.createEmptyMovieClip("flv_mc", this.getNextHighestDepth());
flv_mc.attachAudio(my_ns);
var audio_sound:Sound = new Sound(flv_mc);
// Add volume buttons.
volUp_btn.onRelease = function() {
if (audio_sound.getVolume()<100) {
audio_sound.setVolume(audio_sound.getVolume()+10);
updateVolume();
}
};
volDown_btn.onRelease = function() {
if (audio_sound.getVolume()>0) {
audio_sound.setVolume(audio_sound.getVolume()-10);
updateVolume();
}
};
// Updates the volume.
this.createTextField("volume_txt", this.getNextHighestDepth(), 0, 0, 100,
22);
updateVolume();
function updateVolume() {
volume_txt.text = "Volume: "+audio_sound.getVolume();
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:

Select allOpen in new window

 

by: betagirlPosted on 2008-01-20 at 20:27:25ID: 20703888

@tagit - That confuses me I'm afraid. Where would I put this code? Maybe if I explain how I'm doing this it would help.

In Flash CS3 I'm creating a new Flash File (ActionScript 3.0)

Under components I select "Video" --> FLVPlayback and put an instance of that on the stage

With that selected, under "Parameters"  - I keep all the defaults, and enter the path to my external flv file on the "source" line

Under Components-->Video - I select the MuteButton and drag it to the stage, onto the FLVPlayback screen.

From here, I can export the player and I've got the UI I want, except that the mute button, by default, is off (sound plays along with the video).   What I need to do is set it so that by default, sound is muted - and a user can hit the Mute button to enable the sound.  

Does your code above accomplish this, using the MuteButton component and displaying only it to the user (I don't want to include a volume bar - I was doing so only because I could not figure out how to mute the sound by default).

 

by: tagitPosted on 2008-01-20 at 20:32:14ID: 20703903

sorry i hate to confuse things...

Set an instance name for your FLVComponent something like my_flv.

then in the same keyframe that you have your component have the following code:

// mute the sound initially
my_flv.volume = 0;

 

by: betagirlPosted on 2008-01-20 at 20:56:51ID: 20703995

When you say FLVComponent - do you mean the FLVPlayback or the MuteButton? They are both components.

And where would the script be placed? When I select either of the two components, and bring up the "Actions" window to place the script in there - there's a message saying "Current selection cannot have actions applied to it"

Sorry, I'm sure this is really basic and it's really eluding me. I've not done anything with Flash video in over a year - and then it was very minimal as well.  

 

by: tagitPosted on 2008-01-20 at 20:59:11ID: 20703999

sorry the FLVPlayback.

and for the actions, don't click on any movies or components just click the stage then go to the actions window and add the code

 

by: betagirlPosted on 2008-01-20 at 21:33:10ID: 20704086

With that solution, I will need to add a volume slider so that users can turn up the volume (I added the instance, the code, and without the volume slider, there was no sound throughout the entire video).  I had already done this, using the components and setting the FLVPlayback's volume parameter to 1 (see my first post). However, I don't want to include a volume slider. I want to only include a mute button.  

By default, the MuteButton component loads the MuteButtonOn symbol - the actions associated with it are:

stop();
this.upLinkageID = "MuteButtonOnNormal";
this.overLinkageID = "MuteButtonOnOver";
this.downLinkageID = "MuteButtonOnDown";
this.disabledLinkageID = "MuteButtonOnDisabled";

There are no other actions associated with the other symbols in the MuteButton component (including all the "Off" symbols).

So what I need, is to have the MuteButton component, but instead of it's default rendering with sound enabled, I need the "MuteButtonOffNormal" to display and have the default be no sound, until this button is clicked, enabling the MuteButtonOn symbol, and sound with it.  

 

by: tagitPosted on 2008-01-20 at 21:40:35ID: 20704102

when the user clicks the MuteButton the volumeUpdate event is raised so you can capture this with code to set the volume

var listenerObject:Object = new Object();
listenerObject.volumeUpdate = function(eventObject:Object):Void {
    trace("Volume setting is: " + eventObject.volume);
    // if the volume is muted then enable it for the user, otherwise mute
    if (eventObject.volume == 0) {
        eventObject.volume = 100;
    }
    else {
        eventObject.volume = 0;
    }
};
my_flv.addEventListener("volumeUpdate", listenerObject);
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:

Select allOpen in new window

 

by: betagirlPosted on 2008-01-20 at 21:54:12ID: 20704128

So on the stage, in the actions window I have:

// mute the sound initially
my_flv.volume = 0;

Where does the code you have above go? And how does this affect the toggling and display of the mute button?

 

by: tagitPosted on 2008-01-20 at 22:28:34ID: 20704213

the code above would go in the same place ie in the stage action window.  the mute button should visually toggle automatically

 

by: betagirlPosted on 2008-01-20 at 23:00:29ID: 20704302

Is there anyway you could upload a sample file that does what I'm describing? Adding that code into the actions pane for the stage causes the file to just flicker the Flash icon over and over and over - it never loads the player or the video (when I attempt to test the movie). Conversely, I could upload my project file - if you think that would help.

Thanks!

 

by: tagitPosted on 2008-01-21 at 02:17:14ID: 20704880

prob better if you upload your project file if you don't mind?

 

by: betagirlPosted on 2008-01-21 at 12:12:54ID: 20709200

Thanks for sticking with me on this tagit. Project file is here: http://www.ee-stuff.com/Expert/Upload/getFile.php?fid=6671

 

by: tagitPosted on 2008-01-21 at 15:49:29ID: 20710745

sorry are you able to save as Flash 8

 

by: betagirlPosted on 2008-01-21 at 17:22:36ID: 20711171

Ah. Perhaps this is why your solutions were not working for me. I get this error when trying to play a saved as Flash 8 file -

WARNING: The component 'fl.video.FLVPlayback' requires ActionScript 3.0.

I'm not sure what I upload will be of any use to you - it seems Flash 8 does not have the FLVPlayback component??

New file is here: http://www.ee-stuff.com/Expert/Upload/getFile.php?fid=6673

Thanks!

 

by: tagitPosted on 2008-01-21 at 18:14:49ID: 20711411

Flash 8 has a FLVPlayback component as well.  and i'm experiencing the same problem as you :)

 

by: tagitPosted on 2008-01-21 at 18:17:55ID: 20711424

I've found this on another website: http://www.kirupa.com/forum/showthread.php?t=193603

my_flv.volume = 0;
my_flv._uiMgr._isMuted = true;

it seems that there is no direct method to call to mute the control

 

by: betagirlPosted on 2008-01-21 at 19:43:39ID: 20711756

I found that code, and tried it - but it did not work for me. Will that only work with Flash 8? Did you try that in the file I sent to you and it work?

 

by: tagitPosted on 2008-01-21 at 21:27:56ID: 20712096

i've tried a different way by just adding the MuteButton component and setting the muteButton property of the FLVPlayback to an instance of this component.  Then by capturing the onRelease event of that clip you can set the volume to 100 or 0.  haven't got the skin to change yet though but i'll let you know when i do, very close... :)

 

by: betagirlPosted on 2008-01-23 at 10:33:12ID: 20725987

@tagit - any luck yet?

 

by: betagirlPosted on 2008-01-23 at 20:22:26ID: 20730579

Well, here's how I ended up doing it: (found this tip in the Flash forum at Adobe)

Using ActionScript 2.0 - where "vid" is the instance name of the FLVPlayback component -
added a new layer, and in that layer - this function:

vid.volume = 0;
vid.onPress = function(){
vid.volume = 100;
delete(this.onPress);
}

So it loads the player with the sound muted, but a press anywhere on the video will enable the sound. From there, the mute button toggles correctly.  Note that this is still a hack, as the mute button appears to be off (sound enabled) when the video loads.  Still searching for a way to load the movie with the mute button in the on state (sound disabled, and reflected by the button).  After literally, about 2 days hunting the web and forums and asking around in general, I'm giving up and going with the hack.  

Thanks for your help. Not sure what to do about points and stuff....???

 

by: tagitPosted on 2008-01-23 at 20:24:28ID: 20730591

sorry i haven't got back to you sooner... i'm glad that works for you.  i was still stumped on changing the skin of the mutebutton to show that the sound has been muted even though you can't hear anything.  the mutebutton worked (would turn the sound on & off and also start with the sound off) but didn't change to indicate it's state.

 

by: MattH1Posted on 2008-02-15 at 13:52:40ID: 20906370

This question/problem is the reason why I joined this site. It was disappointing to find that there is no answer to this.
We need to script some code in Flash actionscript 3.0 that will set the UI component muteButton to the selected state when the swf is opened, thus no sound is heard. If the person watching the swf wants to hear sound, then they must click on the mutebutton to unmute the sound, thus the sound is now heard.
To recap: setting the volume = 0 doesn't mute the sound, it just sets the volume to 0 and has nothing to do with the mutebutton status.
If you click on the mutebutton, the sound is muted. If you click on the mute button again, the sound returns to its original value. Even if I keep track of the original volume level myself, the mutebutton graphic still needs to change to the speaker with minus sign "-".

Perhaps this could shed some light on a possible solution:
After further investigation we noticed that the UI Component muteButton is a MovieClip that contains additional layers muteOn and muteOff. If also contains internal movieclips such as MuteButton.MuteButton.On and MuteButton.MuteButton.Off, etc.

There has to be a parameter that can be set to make the mutebutton on or off!

Here is a sample of our process:
I placed the UI component FLVPlayback component on the stage.
I placed the UI component muteButton on the stage, (along with other video playback buttons).
I used actionscript cs3 to load a FLV.
When I play the movie, I need the muteButton to already be in the ON state, so NO sound plays.
(If the viewer wants to here the sound, they must manually click the muteButton to turn OFF, so sound is heard)
I can't manually set flvControl.volume = 0 because I need to maintain volume value, which is how the mutebutton works, because when the muteButton is clicked OFF, the volume returns to it's value prior to being muted. In addition, I can't just set volume to 0 because the mutebutton graphic still needs to be changed to ON state.
Here's a small sample of code:

var flvControl = display; // display is instance name of flvPlayback component on stage
var flvSource = "SphericalObject.flv";
flvControl.source = flvSource;
flvControl.muteButton = mute_btn;

// We need some actionscript here to set the mute Button so no sound plays
// If the viewer wants to here sound also, they
// must manually click the mute button to hear sound.
// The instance name of the mute button is "mute_btn"

flvControl.addEventListener(SoundEvent.SOUND_UPDATE,volumeSlider);
function volumeSlider(event:SoundEvent):void
{      
trace ("volume slider moved");      
trace ("volume = " + flvControl.volume);
}

// this clickHandler does nothing but read values in hopes that a clue might be found
mute_btn.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void
{
trace("mutebutton clicked");
var tsprite:Sprite = Sprite(event.target);
trace ("event.target = " + tsprite);
trace ("event.target.name = " + event.target.name);
}
stop();

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...