CRITICAL FIX: ReinitDevice now uses backend system
PROBLEMA ENCONTRADO: 1. Frontend guardaba backend_type correctamente ✅ 2. Player leía settings al inicio (backend_type = None) ✅ 3. Usuario cambiaba backend en UI → se guardaba en BD ✅ 4. Pero Player en memoria tenía settings VIEJOS ❌ 5. reinit_audio_device usaba legacy CPAL sin backend ❌ SÍNTOMAS: - "Backend system not configured, using legacy CPAL path" - "Device '...' not found, using default" - Audio salía por laptop speakers, no por DAC SOLUCIÓN IMPLEMENTADA: 1. init_device() ahora intenta backend system primero: - Lee thread_settings.backend_type - Si configurado, llama try_init_stream_with_backend() - Fallback a legacy CPAL si falla 2. reinit_audio_device() recarga settings desde BD: - Lee AudioSettings desde database - Actualiza Player.audio_settings en memoria - Luego llama reinit_device() - Garantiza que Player siempre tiene config fresca AHORA FUNCIONARÁ: - Cambiar backend → se guarda → se recarga → se usa - Cambiar device → se guarda → se recarga → se usa - PULSE_SINK se setea correctamente - Audio debe salir por Cambridge DAC TESTING REQUERIDO: Ir a Settings → Audio → Backend: PipeWire → Device: DacMagic Plus Reproducir música → debería salir por DAC
This commit is contained in:
1 parent
e1d56145d1
commit
e74c642831
2 files changed
+33
No files matched your search
@@ -536,8 +536,20 @@ pub fn get_audio_output_status(
|
||||
pub fn reinit_audio_device(
|
||||
device: Option<String>,
|
||||
state: tauri::State<'_, crate::AppState>,
|
||||
audio_settings_state: tauri::State<'_, crate::config::audio_settings::AudioSettingsState>,
|
||||
) -> Result<(), String> {
|
||||
log::info!("Command: reinit_audio_device {:?}", device);
|
||||
|
||||
// Reload settings from database to ensure Player has latest config (including backend_type)
|
||||
if let Ok(store) = audio_settings_state.store.lock() {
|
||||
if let Ok(fresh_settings) = store.get_settings() {
|
||||
if let Ok(mut player_settings) = state.player.audio_settings.lock() {
|
||||
*player_settings = fresh_settings;
|
||||
log::info!("Reloaded audio settings before reinit (backend_type: {:?})", player_settings.backend_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state.player.reinit_device(device)
|
||||
}
|
||||
|
||||
|
||||
@@ -590,7 +590,28 @@ impl Player {
|
||||
};
|
||||
|
||||
// Helper to find and initialize audio device
|
||||
// Try backend system first, fall back to legacy CPAL
|
||||
let init_device = |name: &Option<String>, state: &SharedState| -> Option<(OutputStream, rodio::OutputStreamHandle)> {
|
||||
// Try backend system if configured
|
||||
if let Ok(settings) = thread_settings.lock() {
|
||||
if settings.backend_type.is_some() {
|
||||
// Use a dummy sample rate/channels for reinit (will be set on next play)
|
||||
match try_init_stream_with_backend(&settings, 48000, 2) {
|
||||
Some(Ok(stream)) => {
|
||||
log::info!("Audio output initialized via backend system");
|
||||
return Some(stream);
|
||||
}
|
||||
Some(Err(e)) => {
|
||||
log::warn!("Backend system init failed: {}, falling back to legacy", e);
|
||||
}
|
||||
None => {
|
||||
// Backend not configured, continue to legacy path
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy CPAL path
|
||||
let device = if let Some(ref name) = name {
|
||||
log::info!("Looking for audio device: {}", name);
|
||||
let found = host.output_devices()
|
||||
|
||||
Reference in new issue
Block a user