soundTransform is muting the sound but sound still plays - actionscript-3

I am using the following code, in the last line when I play the sound I can still hear it even when I have transformed it to 0.
var tempTransform:SoundTransform = new SoundTransform(0,0.5);
clickSoundChannel = clickSound.play();
clickSoundChannel.soundTransform = tempTransform;
clickSound.play();

You're calling clickSound.play() twice, and you're only muting the first one.

Related

Playing preloaded MP4

I'm trying to achieve seamless looping of an MP4 (or M4A to be more specific) sound. The usual method of loading, playing to the end, and then seeking to position zero causes a small delay (less than a second) before the second playback begins.
So now I'm trying to preload the sound data and then use NetStream.appendBytes() to append the whole sound data at the end of the original sound, expecting the sound to repeat once. But first, I want to be able to play the sound just once using the appendBytes() method. Here is the code I wrote that doesn't give any errors but doesn't play a sound either:
var data:ByteArray = new SoundData; // SoundData class contains the embedded M4A file data
var connection: NetConnection = new NetConnection();
connection.connect(null);
var stream: NetStream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
stream.client = {};
function onNetStatus(event:NetStatusEvent): void {
trace(event.info.code, stream.time, stream.bytesLoaded, stream.bytesTotal);
}
stream.play(null);
stream.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
stream.appendBytes(data);
Am I using appendBytes() correctly?
I ended up using a hack for achieving apparent seamless looping: loading two sound files through NetStream, playing one, and 100ms before its end, starting to play the other.

Overlapping sound in as3

Okay, so I am making a game, and I can't figure out how to keep the sound track from overlapping. When the game comes to a lose or win screen, I will click "Play again" and the sound will overlap. I have the sound on it's own layer. Here's what I have so far.
var snd_SolidState = new SolidState();
snd_SolidState.play(0,1);
And on Layer 2 Frame 2 and 3, I have:
snd_SolidState.stop();
snd_SolidState = null;
It says "stop" is not a function. So how would I get the song to stop on the lose/win screens? SolidState is the song.
If the code is related to the click of the "Play again" Button, here is the code for those.
mc_again.addEventListener(MouseEvent.MOUSE_UP,upAgain);
function upAgain(e:MouseEvent){
gotoAndStop(1);
}
Can anyone help?
You need to use a SoundChannel to stop your music.
The variable snd_SolidState is a Sound object, Sound doesn't have a stop method implemented; The Sound.play() however, returns a SoundChannel object which does...
So you can store that (the SoundChannel object returned by snd_SolidState.play()), which you can later use to stop the song.
PS: I recommend you start typing your variables (ie: var snd_SolidState:Sound;), that way you force yourself to know which object type you're dealing with and can find reference for it; in this case Sound.play().

When playing back sounds the more sounds that play at once the higher pitch and louder they seem to get

basically what the title says when i play back sounds using the basic
mySound= new Sound();
c = new SoundChannel();
c = mySound.play();
this is in a class that is being set to a mp3 for testing. I did have it generating sound but set it to a mp3 for testing the pitch problem. The more times it is called while the same sound is still playing the higher pitch it seems to become almost becoming louder as well. I thought that was the point of different channels? Is there same way to fix this with soundmixer or something? Thank you
Please don't downvote just because you don't understand what i am asking I see this happening way too often lately.
mySound.play() is returning a new SoundChanel.
c = new SoundChannel();
c = mySound.play();
What you're doing here is assigning a new SoundChanel to c, juste after that, you assigne it an other new SoundChanel.
And assigning a new SoundChanel to c do not make the previous one disappear. It still exist (an thus playing), but c is not refering to it anymore.
Try this:
if(c!=null) // if c has previously be assigned a soundchanel (that might be playing), stop it
c.stop();
c = mySound.play(); // assign new SoundChanel to c and play it

preload html5 audio while it is playing

For HTML5 Audio, let's say you have a list of two songs you want to play. Currently I have it set up so that when the current song stops playing, it loads the new song and plays it. I want to have it so that it loads the next song while the current song is finishing, maybe 20 seconds before the current song finishes. I tried to change the src attribute for the audio object while the song is playing, but that just immediately stops playback for the current song. Is there some other method that allows me to preload the next song while the current song is playing?
You could use jQuery to create a jQuery object:
var nextSong = document.createElement('audio'); //Creates <audio></audio>
nextSong = $(nextSong); //Converts it to a jQuery object
$(nextSong).attr('autoplay') = false; //You don't want this dynamically loaded audio to start playing automatically
$(nextSong).attr('preload') = "auto"; //Make sure it starts loading the file
$(nextSong).attr('src') = url_to_src; //Loads the src
This should start load the song into an element in the browser's memory and when the song is over, call something like:
$(audio).replace(nextSong);
This isn't tested. You probably don't even need jQuery.
This may work without jQuery:
var nextSong = document.createElement('audio');
nextSong.autoplay = 'false';
nextSong.preload = 'auto';
nextSong.src = url_to_src;
Give it a whirl and let me know!
This might be off the mark, but have you tried calling the element's load() method?
http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#loading-the-media-resource
Edit:
Ah, I think I misunderstood the problem. You want to play two songs back to back in the same media element? I'm not sure how feasible that is... it might be easier to place each song in its own Audio element. You could always dynamically generate these, if you're worried about flexibility.

Audio of a specific video swf doesn't stop when I load another URLRequest

I am trying to stop the audio of the video swf and I can't get it to stop. Here is my code for loading the file:
var myLoader:Loader= new Loader();
myLoader.x=420;
myLoader.y=200;
// boolean variable set for use below in our function
var screenCheck:Boolean = false;
//These three linces keep stafe elements the same size, so they don't distort
var swfStage:Stage = this.stage;
video_btn.addEventListener(MouseEvent.CLICK,contentvideo);
function contentvideo (event:MouseEvent):void{
myLoader.load(new URLRequest("prevideo.swf"));
addChild(myLoader);
movie_btn.stop();
movie_btn.visible=false;
}
Now I have other functions that load different URLRequest and when they are loading, the audio keeps playing. Do I have to add a line of code to them? I also have an MP3 player and tried SoundMixer.stopAll(). I still need the mp3 player to keep playing.
I'm not familiar with what you're doing but just looking at the code and given the problem you're experiencing I wonder if that
addChild(myLoader);
has anything to do with it. It seems like the kind of thing that could easily create multiple child objects which is why you continue to experience the sound play back. Is there a removeChild[0] option or something?
A shot in the dark I know but I thought I'd offer the possibility anyway.