Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SoundSource: Fix broken file type detection if file suffix is misleading
If a file is named `foo.wav` but actually contains MP3 data, `SoundSource::getTypeFromFile` should return "mp3", not "wav". This behavior is expected and already tested in `SoundSourceProxyTest.getTypeFromFile`, but due to a bug in our test file creation code, the test operated on a wrong file name and passed although the behavior was broken and the function would just return "wav" in the example above. The reason for this is that QMimeDatabase only looks at the file name when the file suffix is misleading, and thus cannot detect that the file is actually an MP3 file: > The default matching algorithm looks at both the file name and the > file contents, if necessary. The file extension has priority over the > contents, but the contents will be used if the file extension is > unknown, or matches multiple MIME types. > > Source: https://doc.qt.io/qt-5/qmimedatabase.html#mimeTypeForFile This commit fixes `SoundSource::getTypeFromFile` to work as expected by using the file *content* instead of the file name for determining the file type.
- Loading branch information