// Copyright 2014-2025 Jesper Larsson
//
// This file is part of Klipspringer, <https://klipspringer.avadeaux.net/>
//
// Klipspringer is free software: you can redistribute it and/or modify it under the terms of the
// GNU General Public License as published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// Klipspringer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with Klipspringer. If
// not, see <https://www.gnu.org/licenses/>.

package net.avadeaux.klipspringer.codec.spi;

import java.io.IOException;
import javax.sound.sampled.AudioFileFormat;
import net.avadeaux.klipspringer.codec.*;

/** Plugin to be used as <a
  * href="https://docs.oracle.com/javase/8/docs/technotes/guides/sound/programmer_guide/chapter14.html">audio
  * service provider</a>.
  */
public class FlacAudioFileReader extends KlipspringerAudioFileReader {
    private final static AudioFileFormat.Type FLAC = new AudioFileFormat.Type("FLAC", "flac");
    private final static AudioFileFormat.Type OGA = new AudioFileFormat.Type("Ogg FLAC", "oga");

    /** Constructor. */
    public FlacAudioFileReader() {
        super(new DecoderAudioInputStream.DecoderFactory() {
                public AudioDecoder createAudioDecoder(String fileName, AudioDecoder.Target target) throws IOException {
                    return new FlacDecoder(fileName, target);
                }
                public AudioFileFormat.Type type(String fileName) { return fileName.endsWith(".oga") ? OGA : FLAC; }
            });
    }
}
