package de.ctdo.crashtest.domotics;

import de.ctdo.crashtest.log.Logger;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

public class ExtraSoundControl implements IExtraSoundControl {


    @Override
    public void playJingle(final String name) {

        System.out.println("ExtraSoundControl: playJingle name=" + name );

        Runnable r = new Runnable() {
            @Override
            public void run() {
                try {
                    HttpClient client = new DefaultHttpClient();
                    HttpGet get = new HttpGet("http://dampfradio.raum.ctdo.de/controller.php?command=jingle&mpd=mpd1&arg=" +name);


                    client.execute(get);
                    get.abort();

                } catch (UnsupportedEncodingException e) {
                    Logger.sLog("ExtraSoundControl error: " + e.getMessage());
                } catch (ClientProtocolException e) {
                    Logger.sLog("ExtraSoundControl error: " + e.getMessage());
                } catch (IOException e) {
                    Logger.sLog("ExtraSoundControl error: " + e.getMessage());
                }
            }
        };

        new Thread(r).start();
    }
}
