Fix ALAC playback by defaulting to stereo when channel info missing

ALAC files (and some other formats) don't include channel information in
the initial codec params, causing playback to fail with error:
'No channel info in codec params'

Changed to use .unwrap_or(2) instead of .ok_or_else() to default to
stereo (2 channels) which is the most common case and matches the
behavior in metadata extraction.

Fixes playback of ALAC (.m4a) files in Local Library.
This commit is contained in:
vicrodh committed 2026-01-19 20:38:38 -06:00
1 parent dec6eab109
commit cdaf02bf3a
1 file changed
+4 -1
+4 -1
View File
@@ -222,9 +222,12 @@ fn extract_audio_metadata(data: &[u8]) -> Result<(u32, u16), String> {
let sample_rate = track.codec_params.sample_rate
.ok_or_else(|| "No sample rate in codec params".to_string())?;
// ALAC and some other formats don't include channel info in initial codec params
// Default to stereo (2 channels) which is the most common case
let channels = track.codec_params.channels
.map(|c| c.count() as u16)
.ok_or_else(|| "No channel info in codec params".to_string())?;
.unwrap_or(2);
Ok((sample_rate, channels))
}