tabs for sounds added

This commit is contained in:
2026-02-15 22:03:15 +01:00
parent 0eacdbf973
commit 702eba2370
6 changed files with 256 additions and 157 deletions
+31 -6
View File
@@ -3,10 +3,16 @@ import os
import json
import logging
import shutil
import threading
from logging.handlers import TimedRotatingFileHandler
from datetime import datetime, timedelta
from flask import Flask, render_template, redirect, url_for, send_from_directory, request, jsonify
import pygame
# pygame einmalig initialisieren (am besten global)
pygame.mixer.init(frequency=44100, size=-16, channels=2, buffer=512)
pygame.mixer.music.set_volume(0.8) # Standard 80 %
# Logging-Verzeichnis (muss VOR cleanup_old_log_dirs definiert werden!)
LOG_DIR = 'logs'
os.makedirs(LOG_DIR, exist_ok=True)
@@ -540,12 +546,6 @@ def api_reconnect():
return jsonify({"success": False, "message": str(e)}), 500
import pygame
import threading
# pygame einmalig initialisieren (am besten global)
pygame.mixer.init()
@app.route('/api/play_sound', methods=['POST'])
def api_play_sound():
try:
@@ -588,6 +588,31 @@ def api_play_sound():
return jsonify({"success": False, "message": str(e)}), 500
@app.route('/api/set_volume', methods=['POST'])
def api_set_volume():
try:
data = request.get_json()
vol = float(data.get('volume', 0.8))
vol = max(0.0, min(1.0, vol))
pygame.mixer.music.set_volume(vol)
logger.info(f"Volume auf {vol} gesetzt")
return jsonify({"success": True})
except Exception as e:
logger.error(f"Volume-Fehler: {e}")
return jsonify({"success": False, "message": str(e)}), 500
@app.route('/api/stop_sound', methods=['POST'])
def api_stop_sound():
try:
pygame.mixer.music.stop()
logger.info("Aktueller Sound gestoppt")
return jsonify({"success": True})
except Exception as e:
logger.error(f"Stop-Sound-Fehler: {e}")
return jsonify({"success": False, "message": str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)