package eu.ydp.empiria.player.client.controller.extensions.internal.sound;

import eu.ydp.empiria.flash.gwtflashaudio.client.FlashSound;
import eu.ydp.empiria.flash.gwtflashaudio.client.FlashSoundFactory;
import eu.ydp.empiria.flash.gwtflashaudio.client.event.FlashSoundCompleteEvent;
import eu.ydp.empiria.flash.gwtflashaudio.client.event.FlashSoundCompleteHandler;
import eu.ydp.empiria.flash.gwtflashaudio.client.event.FlashSoundPlayEvent;
import eu.ydp.empiria.flash.gwtflashaudio.client.event.FlashSoundPlayHandler;

public class SoundExecutorSwf implements SoundExecutor {

	protected FlashSound currSound;
	protected boolean playing = false;
	protected SoundExecutorListener listener;
	protected String playerPathDir = null;
	
	public SoundExecutorSwf(){
		FlashSoundFactory.init();
	}
	
	@Override
	public void play(String src) {

		if (playing)
			stop();
		
		currSound = FlashSoundFactory.createSound(src);
		
		currSound.addFlashSoundPlayHandler(new FlashSoundPlayHandler() {
			
			@Override
			public void onFlashSoundPlay(FlashSoundPlayEvent event) {
				if (listener != null)
					listener.onPlay();
				playing = true;
			}
		});
		
		currSound.addFlashSoundCompleteHandler(new FlashSoundCompleteHandler() {
			
			@Override
			public void onFlashSoundComplete(FlashSoundCompleteEvent event) {
				onSoundStop();
			}
		});
		
		currSound.playSound();

	}

	@Override
	public void stop() {
		if (playing){
			if (currSound != null)
				currSound.stopSound();
			onSoundStop();
		}
	}
	
	private void onSoundStop(){
		playing = false;
		if (listener != null)
			listener.onSoundFinished();
		currSound.freeSound();
	}

	@Override
	public void setSoundFinishedListener(SoundExecutorListener listener) {
		this.listener = listener;
	}
	
}

@@ -89,38 +89,32 @@
 ydp.empiria.
-flash.
 gwtflash
 audio.client
@@ -93,37 +93,37 @@
 empiria.gwtflash
-audio
+media
 .client.FlashSou
@@ -145,38 +145,32 @@
 ydp.empiria.
-flash.
 gwtflash
 audio.client
@@ -149,37 +149,37 @@
 empiria.gwtflash
-audio
+media
 .client.FlashSou
@@ -208,38 +208,32 @@
 ydp.empiria.
-flash.
 gwtflash
 audio.client
@@ -212,37 +212,37 @@
 empiria.gwtflash
-audio
+media
 .client.event.Fl
@@ -236,37 +236,37 @@
 ient.event.Flash
-Sound
+Media
 CompleteEvent;%0D%0A
@@ -283,38 +283,32 @@
 ydp.empiria.
-flash.
 gwtflash
 audio.client
@@ -287,37 +287,37 @@
 empiria.gwtflash
-audio
+media
 .client.event.Fl
@@ -315,29 +315,29 @@
 .event.Flash
-Sound
+Media
 CompleteHand
@@ -360,38 +360,32 @@
 ydp.empiria.
-flash.
 gwtflash
 audio.client
@@ -364,37 +364,37 @@
 empiria.gwtflash
-audio
+media
 .client.event.Fl
@@ -392,29 +392,29 @@
 .event.Flash
-Sound
+Media
 PlayEvent;%0D%0A
@@ -439,22 +439,16 @@
 ria.
-flash.
 gwtflash
 audi
@@ -447,13 +447,13 @@
 lash
-audio
+media
 .cli
@@ -463,29 +463,29 @@
 .event.Flash
-Sound
+Media
 PlayHandler;
@@ -922,29 +922,29 @@
 und.addFlash
-Sound
+Media
 PlayHandler(
@@ -948,29 +948,29 @@
 er(new Flash
-Sound
+Media
 PlayHandler(
@@ -1026,29 +1026,29 @@
 ndPlay(Flash
-Sound
+Media
 PlayEvent ev
@@ -1161,29 +1161,29 @@
 und.addFlash
-Sound
+Media
 CompleteHand
@@ -1191,29 +1191,29 @@
 er(new Flash
-Sound
+Media
 CompleteHand
@@ -1277,29 +1277,29 @@
 mplete(Flash
-Sound
+Media
 CompleteEven
@@ -1363,21 +1363,16 @@
 und.play
-Sound
 ();%0D%0A%0D%0A%09
@@ -1473,21 +1473,16 @@
 und.stop
-Sound
 ();%0D%0A%09%09%09
@@ -1632,21 +1632,16 @@
 und.free
-Sound
 ();%0D%0A%09%7D%0D

update executor due to gwtFlashMedia dependency change bug 66263