// 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;

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

public class DeviceCommandInterface extends CommandInterface {
    private final DeviceFeeder feeder;

    public DeviceCommandInterface(DeviceFeeder feeder) {
        super(null, 0);
        cmds.put("set_played_get_status", (q, w) -> {
                AudioStream stream = streamHandles.get(q.value("player_id", "undefined"));
                if (stream == null) {
                    w.append("{\"err\":\"unknown player_id\"}");
                    return;
                }
                double time = q.doubleValue("time", 0);
                stream.playedMillis((long) (time*1000.0 + 0.5));
                w.append("{");
                feeder.deviceStatus(w);
                String bitrate = stream.quality();
                if (bitrate != null) { w.append(",\"bitrate\":\""+bitrate+"\""); }
                w.append("}");
            });
        cmds.put("end", (q, w) -> {
                AudioStream stream = streamHandles.get(q.value("player_id", "undefined"));
                if (stream != null) { stream.close(); }
            });
        cmds.put("start_record", (q, w) -> {
                feeder.startRecord();
            });
        cmds.put("stop_record", (q, w) -> {
                feeder.stopRecord();
            });
        cmds.put("set_format", (q, w) -> {
                feeder.setFormat(Track.rawFormat(q.value("format", "")));
            });
        cmds.put("quit", (q, w) -> {
                System.exit(0);
            });
        cmds.put("set_reclimit", (q, w) -> {
                double minutes = q.doubleValue("minutes", -1);
                if (minutes >= 0) { feeder.setRecLimit(60*minutes); }
            });
        this.feeder = feeder;
    }

    protected void fetchStream(Query q, Device.Player.Factory streamFact) throws IOException {
        AudioStream stream = streamHandles.get(q.value("player_id", ""));
        if (stream != null) { stream.close(); }
        feeder.fetchStream(streamFact);
    }
}

Version: v4.3.2.2 (2026-05-16T17:03:34+02:00)
Raw file
Source code overview
Klipspringer home