• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

Sound Toggle For Video Clip

Hi all.
Before I inquired about a play/pause toggle button for a video clip, which I got help with.
Now I am having trouble with a play/pause toggle for the sound in that video clip, as opposed to a toggle for independent sound. My button pauses the sound, but won't restart it.

I have placed the video clip in a movie clip in _root called mcVideo.
On frame 1 of _root, I set:

sounds = 0;
firstSound=new Sound(_root.mcVideo);

Then, on the mute button (also on _root), I set:

on(release){
     
if (sounds == 0) {
  _root.firstSound.stop();
  _root.sounds = 1;
  }
 
 else {
  _root.firstSound.start();
  _root.sounds = 0;
 }
 
}


Thank you
0
rimbaud
Asked:
rimbaud
  • 3
  • 2
1 Solution
 
ZefferCommented:
change the 'else' to another 'if statement ..

on(release){
   
if (sounds == 0) {
 _root.firstSound.stop();
 _root.sounds = 1;
 }
 
if (sounds == 1) {
 _root.firstSound.start();
 _root.sounds = 0;
 }

}

Z

0
 
henrywwCommented:
hi all,

i had tried using stop/start with a movieclip target, but i can't get it to start playing either.

sorry if i am ignorant, i don't see any different between using the "else" and the extra "if".

in this particular case, if the sound is a loop then i would sugguest set the volume to 0 then 100 again to as to turn it on/off

// frame1 _root
snd = new Sound(_root.myMc);
sndstop = 0;

// button
on (release) {
     if (_root.sndstop == 0) {
     _root.sndstop = 1
     _root.snd.setVolume(0);
     trace("volume = " + _root.snd.getVolume());
     } else {
     _root.sndstop = 0
     _root.snd.setVolume(100);
     trace("volume = " + root.snd.getVolume());
     }
}


otherwise if u really have to stop & start at the same position. use sound object & attach the sound.

//frame 1 _root
var snd2Pos = 0;
var snd2 = new Sound()
snd2.attachSound("s");
snd2.onSoundComplete = function (){
     snd2.start(0,1);    
}

// sound toggle button
on (release) {
     if (_root.snd2Pos ==0) {
     _root.snd2Pos = _root.snd2.position / 1000
     _root.snd2.stop("s");
     trace("stop :"+  _root.snd2Pos);
     } else {
     trace("play :"+  _root.snd2Pos);
     _root.snd2.start(_root.snd2Pos,1);
     _root.snd2Pos = 0
     }
}
snd2.start(0,1);


cheers
0
 
henrywwCommented:
sorry the correct post should be

otherwise if u really have to stop & start at the same position. use sound object & attach the sound.

//frame 1 _root
var snd2Pos = 0;
var snd2 = new Sound()
snd2.attachSound("s");
snd2.onSoundComplete = function (){
    snd2.start(0,1);    
}
snd2.start(0,1); // **** this line here

// sound toggle button
on (release) {
    if (_root.snd2Pos ==0) {
    _root.snd2Pos = _root.snd2.position / 1000
    _root.snd2.stop("s");
    trace("stop :"+  _root.snd2Pos);
    } else {
    trace("play :"+  _root.snd2Pos);
    _root.snd2.start(_root.snd2Pos,1);
    _root.snd2Pos = 0
    }
}

copy & paste error ... he he he
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rimbaudAuthor Commented:
Thanks guys, but no luck yet.

Zeffer, the change in keyword to "if" didn't change anything.

Henry, when I implement your code, the sound doesn't stop and I get the error message "stop :0"
Maybe I implemented it wrong?
The movie clip is called "mcVideo," and I don't see that represented in your code. I also tried passing the new Sound() object the parameter _root.mcVideo, but that didn't work.

Again, this is a video clip with voiceover sound that I placed inside a movie clip. I have had success turning the sound off with the simple code listed in my first email, but can't turn it back on after that.
0
 
henrywwCommented:
sorry ... i was not using ur code, the clip names are different .. i was just giving an example

the fact that, if u have a movieclip with an event sound, u can stop it but it won't start again ... i don't know why, it maybe a bug or something.

ok if u want it exactly in ur code ...

sounds = 0;
firstSound=new Sound(_root.mcVideo);

on(release){
   
if (sounds == 0) {
 _root.firstSound.setVolume(0);
 _root.sounds = 1;
 }
 
else {
 _root.firstSound.setVolume(100);
 _root.sounds = 0;
}
}
that's how i'd turn off the volume instead


as for the second methond mentioned, here u will have to remove the event sound from the movieclip and export the sound, call "s" or whatever u like

//frame 1 _root
var snd2Pos = 0;
var snd2 = new Sound()
snd2.attachSound("s"); // attach the sound from library
// if u don't need the loop remove the whole function
snd2.onSoundComplete = function (){
   snd2.start(0,1);     // looping the sound
}

//starts playing
snd2.start(0,1);
// i suppose u can start ur movieclip here too, so the sound & the movie can sync

// sound toggle button
on (release) {
   if (_root.snd2Pos ==0) {
   // stop the sound and remember where it is stopped
   _root.snd2Pos = _root.snd2.position / 1000
   // now if u want to stop the movieclip as well
   // do this _root.mcVideo.stop();
   _root.snd2.stop("s");
   } else {
  // start again
  // and to start the movieclip _root.mcVideo.play();
   _root.snd2.start(_root.snd2Pos,1);
   _root.snd2Pos = 0
   }
}

use the attachSound u can stop /start the sound object, but then u will have to manually stop the movieclip as well if it is a VO, ... synchronise the sound & movie is also a very tricky thing, so u need to fine tune it and adjust the frame rate etc ...

cheers
0
 
rimbaudAuthor Commented:
The first method works great and is actually fine for my purposes. But the second method is great to know for the future. Many thanks!

-rimbaud
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now