Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BCR sometimes incorrectly uses .mp3 file extension #292

Closed
chenxiaolong opened this issue Apr 14, 2023 · 1 comment · Fixed by #293
Closed

BCR sometimes incorrectly uses .mp3 file extension #292

chenxiaolong opened this issue Apr 14, 2023 · 1 comment · Fixed by #293
Assignees
Labels
bug Bug in BCR itself

Comments

@chenxiaolong
Copy link
Owner

From #284 (comment):

04-11 18:34:20.462  5628  8743 D OutputDirUtils: Creating 20230411_183403.682-0600_conference_<conference phone numbers>_<conference contact names>.mp3 with MIME type audio/mpeg in content://com.android.externalstorage.documents/tree/primary%3AAudioRecordings%2FBasicCallRecorder/document/primary%3AAudioRecordings%2FBasicCallRecorder

It occurs to me now that I ran into the same problem the other night when I briefly messed with filename formats. To reproduce, simply create a bcr.properties that contains only "filename.1.suffix = Test". Gives me a .mp3 every time.

@chenxiaolong
Copy link
Owner Author

chenxiaolong commented Apr 14, 2023

Ugh, this is an Android bug/inconsistency:

  • MimeTypeMap.getSingleton().getExtensionFromMimeType("audio/mp4") returns m4a
  • MimeTypeMap.getSingleton().getMimeTypeFromExtension("m4a") returns audio/mpeg
  • MimeTypeMap.getSingleton().getExtensionFromMimeType("audio/mpeg") returns mp3

This becomes a problem any time the output file needs to be renamed (eg. custom filename template or contact name changed during the call, etc.).

The flow that causes the issue:

  1. When creating a new file, Android's storage access framework is responsible for adding the file extension. BCR asks it to create <filename> with the audio/mp4 MIME type and it creates <filename>.m4a.
  2. Something requires BCR to rename the output file.
  3. Android's SAF is terribly inconsistent, so when renaming files, the app is responsible for specifying the file extension, not the framework (EDIT: but only for file:// paths...). BCR queries for the current file type, which Android incorrectly reports as audio/mpeg and then uses that to determine and append the (incorrect) file extension mp3.

This should be pretty easy to fix. When renaming a file, instead of asking Android for the file type, we'll just specify it since we know what it should be.

chenxiaolong added a commit that referenced this issue Apr 14, 2023
…xtension when renaming

MimeTypeMap's getExtensionFromMimeType() and getMimeTypeFromExtension()
are not consistent with each other. Querying the extension for
`audio/mp4` returns `m4a` as expected, but querying the MIME type for
`m4a` returns `audio/mpeg`, which is associated with the `mp3`
extension.

Due to this, whenever an output file needed to be renamed, files that
originally had the `m4a` extension would get changed to `mp3`. This
commit fixes the issue by removing the whole extension -> MIME type ->
extension round trip when renaming files. Instead, it just appends
everything after the last dot from the original filename when renaming.

Fixes: #292

Signed-off-by: Andrew Gunnerson <[email protected]>
PatrykMis pushed a commit to PatrykMis/BAR that referenced this issue Jun 1, 2023
…xtension when renaming

MimeTypeMap's getExtensionFromMimeType() and getMimeTypeFromExtension()
are not consistent with each other. Querying the extension for
`audio/mp4` returns `m4a` as expected, but querying the MIME type for
`m4a` returns `audio/mpeg`, which is associated with the `mp3`
extension.

Due to this, whenever an output file needed to be renamed, files that
originally had the `m4a` extension would get changed to `mp3`. This
commit fixes the issue by removing the whole extension -> MIME type ->
extension round trip when renaming files. Instead, it just appends
everything after the last dot from the original filename when renaming.

Fixes: chenxiaolong#292

Signed-off-by: Andrew Gunnerson <[email protected]>
chenxiaolong added a commit that referenced this issue Jul 2, 2023
This fixes a regression in #361, which reintroduced #292/#293.

Fixes: #367

Signed-off-by: Andrew Gunnerson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in BCR itself
Projects
None yet
1 participant