package org.gamefolk.roomfullofcats;

import javafx.scene.media.AudioClip;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;

public class DesktopSoundProvider implements SoundProvider {
    @Override
    public Sound loadSound(String filename) {
        return new DesktopSound(filename);
    }

    @Override
    public MusicPlayer loadMusic(String filename) {
        return new DesktopMusicPlayer(filename);
    }
}

class DesktopMusicPlayer implements MusicPlayer {
    private final MediaPlayer mediaPlayer;

    public DesktopMusicPlayer(String filename) {
        Media media = new Media(getClass().getResource(filename).toString());
        mediaPlayer = new MediaPlayer(media);
    }

    @Override
    public void play() {
        mediaPlayer.play();
    }

    @Override
    public void setCycleCount(int value) {
        mediaPlayer.setCycleCount(value);
    }

    @Override
    public void stop() {
        mediaPlayer.stop();
    }
}

class DesktopSound implements Sound {
    private final AudioClip clip;

    public DesktopSound(String filename) {
        clip = new AudioClip(RoomFullOfCatsApp.class.getResource(filename).toString());
    }

    @Override
    public void play() {
        clip.play();
    }

    @Override
    public void stop() {
        clip.stop();
    }

    @Override
    public void setCycleCount(int count) {
        clip.setCycleCount(count);
    }

    @Override
    public boolean isPlaying() {
        return clip.isPlaying();
    }
}

@@ -461,25 +461,22 @@
 cPlayer 
-implement
+extend
 s MusicP
@@ -733,32 +733,37 @@
 public void play
+Music
 () %7B%0A        med
@@ -987,25 +987,22 @@
 opSound 
-implement
+extend
 s Sound 
@@ -1182,32 +1182,32 @@
 %0A%0A    @Override%0A
-
     public void 
@@ -1210,16 +1210,21 @@
 oid play
+Sound
 () %7B%0A   

fix desktop sound implementation