Skip to content

Tag: Музика

How to put a sound on your website?

I use flash to achieve this. Create a new flash file with AS3. Create two buttons which will be placed one above the other. The stop button instance is called xstop and the play button instance is called xplay.

And this is the code:

//think of the soundchannel as a speaker system and the sound as an mp3 player
var soundChannel:SoundChannel = new SoundChannel();
var sound:Sound = new Sound(new URLRequest("http://www.kavdesign.net/sites/stgeorge/birds1.mp3"));

xstop.addEventListener(MouseEvent.CLICK, clickStop);
xplay.addEventListener(MouseEvent.CLICK, clickPlay);

playMusic();

function clickPlay(evt:MouseEvent) {
	playMusic();
}

function clickStop(evt:MouseEvent) {
		soundChannel.stop();
		soundChannel.removeEventListener(Event.SOUND_COMPLETE, loopMusic);
		xstop.visible = false;
		xplay.visible = true;
}

function playMusic():void
	{
		 soundChannel = sound.play();
		 soundChannel.addEventListener(Event.SOUND_COMPLETE, loopMusic);
		 xstop.visible = true;
		 xplay.visible = false;
	}

function loopMusic(e:Event):void
	{
		 if (soundChannel != null)
		 {
			  soundChannel.removeEventListener(Event.SOUND_COMPLETE, loopMusic);
			  playMusic();
		 }
	}