/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import logger.OhmLogger;

/**
 * https://docs.oracle.com/javase/tutorial/sound/playing.html
 *
 * @author Jan
 */
public class AudioRinging
{
  private AudioInputStream stream;
  private AudioFormat format;
  private DataLine.Info info;
  private Clip clip;
  private File audioFile;
  
  private static final Logger lgAudioRing = OhmLogger.getLogger();
  
  public AudioRinging()
  {
    //Normalerweise so da Betriebssystemunabhängig aber ka wo der Fehler ist
    //String file = (File.separator+"phone"+File.separator+"SoundDateien"+ File.separator+"RingingPhone.wav");
    audioFile = new File("C:\\Users\\Tim\\Desktop\\VoIP PA\\project\\VoIPProjekt\\src\\SoundDateien\\RingingPhone.wav");
    try
    {
      format = AudioSystem.getAudioInputStream(audioFile).getFormat();
      info = new DataLine.Info(Clip.class, format);
    }
    catch (Exception ex)
    {
      lgAudioRing.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
  public void startRinging()
  {
    try
    {
      stream = AudioSystem.getAudioInputStream(audioFile);;
      clip = (Clip) AudioSystem.getLine(info); 
      clip.open(stream);
      clip.start();
    }
    catch (Exception ex)
    {
      lgAudioRing.getLogger(SIPmodel.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
  public void endRinging()
  {
    clip.stop();
    clip.close();
  }
}
