Repository navigation
Conversation
Android's media scanner can index .opus files under the files table without classifying them as audio on some OEM skins, so MediaStore.Audio returned zero rows and the Audio tab stayed hidden even though playback worked. Merge MediaStore.Audio, MediaStore.Files (audio MIME types plus every supported audio extension), and a bounded filesystem fallback. Files-table rows without tags use their parent folder as the album, and missing durations are filled with MediaInfo using four permits. Verification: :app:compileStandardDebugKotlin and :app:testStandardDebugUnitTest (offline), git diff --check.
Reviewer's GuideSchema and migrationsThe schema snapshot records the database schema associated with this change.
ImplementationThe audio scan utilities merge MediaStore sources and a bounded filesystem fallback, detect audio, construct tracks, and enrich missing durations.
UIThe main screen runs the audio-presence probe only when the Audio tab is enabled.
DocumentationThe unreleased changelog announces that audio files skipped by Android's media scanner now appear in the Audio tab.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Deploying mpvium with
|
| Latest commit: |
9705df9
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://17619b93.mpvium.pages.dev |
| Branch Preview URL: | https://issue-194.mpvium.pages.dev |
Linked issuesChecked at commit 9705df9 #194 feat: Detect audio files (opus) · 0 of 1 met · 1 to check by hand
|
There was a problem hiding this comment.
Hey - I've found 10 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt" line_range="163" />
<code_context>
- Log.e(TAG, "Error scanning MediaStore for audio", e)
+ scanAudioFromMediaStore(context, tracksByPath)
+ scanAudioFromMediaStoreFiles(context, tracksByPath)
+ if (tracksByPath.isEmpty()) {
+ scanAudioFromFileSystem(context, tracksByPath)
}
</code_context>
<issue_to_address>
**Unindexed audio stays missing**
When mediaStore contains at least one audio track and another supported audio file is absent from its queried tables, `scanAudio` runs `scanAudioFromFileSystem` only when `tracksByPath` is empty, so any indexed track suppresses the fallback and the unindexed file stays out of the Audio tab.
Run `scanAudioFromFileSystem` alongside the MediaStore scans and deduplicate the resulting tracks.
Also at `UNRELEASED.md:21`.
</issue_to_address>
### Comment 2
<location path="app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt" line_range="266-269" />
<code_context>
+ ?: queryFilesTable(context, FILES_BASIC_PROJECTION)
+ ?: return
+
+ cursor.use {
+ val columns = TrackColumns(it)
+ while (it.moveToNext()) {
+ val track = buildTrack(
+ cursor = it,
+ columns = columns,
</code_context>
<issue_to_address>
**Audio library fails to load**
When the files-table provider returns a cursor but throws while advancing it, reading a row, or building a track, `scanAudioFromMediaStoreFiles` lets the exception escape, so `scanAudio` stops before it can return collected tracks or run the filesystem fallback, and the Audio library fails to load.
Catch errors while consuming the files-table cursor so the scan can retain available tracks and continue.
</issue_to_address>
### Comment 3
<location path="app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt" line_range="500" />
<code_context>
+ val album = file.parentFile?.name?.takeIf { it.isNotBlank() } ?: "Unknown Album"
+
+ return LocalAudioTrack(
+ id = file.absolutePath.hashCode().toLong(),
+ title = file.nameWithoutExtension,
+ displayName = file.name,
</code_context>
<issue_to_address>
**Audio list keys collide**
When the filesystem fallback finds two distinct files whose absolute paths have the same Java string hash, `buildTrackFromFile` uses the path hash as `id`, so both tracks receive the same lazy-list key and Compose throws instead of displaying them.
Assign fallback tracks IDs that are unique for distinct files rather than using only the path hash.
</issue_to_address>
### Comment 4
<location path="app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt" line_range="167" />
<code_context>
+ scanAudioFromFileSystem(context, tracksByPath)
}
+ val tracks = enrichMissingDurations(context, tracksByPath.values.toList())
+
// Group into albums (ID from album + artist, never from title alone)
</code_context>
<issue_to_address>
**Older scans overwrite newer library**
When two refreshes overlap, a newer one finishes before an older scan, the older `AudioRepository.refresh()` finishes last and replaces `_libraryData` with its earlier scan result, even after a newer refresh has already published current tracks; the Audio tab then shows stale library contents until another refresh.
Serialize audio scans or publish results only when their refresh generation is still current.
</issue_to_address>
### Comment 5
<location path="app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt" line_range="394" />
<code_context>
+ }
+
+ private fun trackKey(track: LocalAudioTrack): String =
+ track.path.ifBlank { "${track.displayName}|${track.size}" }
+
+ // ==========================================================================
</code_context>
<issue_to_address>
**Distinct tracks are discarded**
When two distinct tracks have blank paths and identical display names and sizes, `trackKey` gives both tracks the same `displayName|size` key, so `putIfAbsent` discards the later track and the library omits it.
Use a key that distinguishes distinct pathless tracks.
</issue_to_address>
### Comment 6
<location path="app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt" line_range="515" />
<code_context>
+ size = size,
+ sizeFormatted = VideoScanUtils.formatFileSize(size),
+ path = file.absolutePath,
+ uri = Uri.fromFile(file),
+ albumArtUri = null,
+ mimeType = FileTypeUtils.getAudioMimeTypeFromExtension(extension),
</code_context>
<issue_to_address>
**Fallback durations stay zero**
When a filesystem-only track has no indexed duration, `enrichMissingDurations` passes the `file://` URI from `buildTrackFromFile` to `MediaInfoOps.extractBasicMetadata`, which opens it with `ContentResolver.openFileDescriptor`; that lookup fails and the track keeps duration `0`.
Read filesystem-only track metadata from the file path or another URI form supported by the metadata reader.
Also at `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:567`.
</issue_to_address>
### Comment 7
<location path="app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt" line_range="287" />
<code_context>
+ context.contentResolver.query(
+ FILES_URI,
+ projection,
+ AUDIO_FILES_SELECTION,
+ null,
+ "${MediaStore.Files.FileColumns.DISPLAY_NAME} ASC",
</code_context>
<issue_to_address>
**Hidden audio rows enter library**
When `MediaStore.Files` contains a supported audio row under a hidden, skipped, or `.nomedia` folder, `queryFilesTable` selects matching MIME types and extensions without applying the hidden-folder or `.nomedia` exclusions used by the filesystem walk, so matching rows already present in `MediaStore.Files` are added to the visible library.
Apply the same exclusion policy to files-table results before adding tracks.
</issue_to_address>
### Comment 8
<location path="app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt" line_range="406" />
<code_context>
+ return fileSystemProbeResult
+ }
+
+ val found = audioSearchRoots(context).any { containsAudioFile(it, 0) }
+ fileSystemProbeTime = now
+ fileSystemProbeResult = found
</code_context>
<issue_to_address>
**Hidden audio gets exposed**
When a common search-root directory such as Music or Downloads contains `.nomedia` and audio files directly inside it, `containsAudioFile` and `collectAudioFiles` apply `shouldSkipFolder` only to child directories, not to the roots passed in; audio directly inside a root containing `.nomedia` is therefore reported by the probe and added to the Audio tab.
Check whether each search root should be skipped before probing or collecting its contents.
Also at `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:438`.
</issue_to_address>
### Comment 9
<location path="app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt" line_range="486" />
<code_context>
+ }
+
+ // Then the whole volume, so audio in custom folders is not missed.
+ paths.add(primaryStorage.absolutePath)
+ for (volume in StorageVolumeUtils.getExternalStorageVolumes(context)) {
+ StorageVolumeUtils.getVolumePath(volume)?.let { paths.add(it) }
</code_context>
<issue_to_address>
**Audio probe walks the whole volume**
When mediaStore has no audio rows and the common directories do not contain an audio file, `audioSearchRoots` includes the primary storage root, and `containsAudioFile` recursively traverses its directories. When MediaStore has no audio and the early directories contain none, the presence check enumerates the entire accessible volume up to the depth limit, delaying the Audio tab decision on devices with large storage trees.
Bound the probe by elapsed time or number of visited entries, or restrict it to likely media locations instead of recursively walking the whole volume.
Also at `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:423`.
</issue_to_address>
### Comment 10
<location path="UNRELEASED.md" line_range="21" />
<code_context>
### Fixed
+- Audio files Android's media scanner skips, including `.opus` downloads, now appear in the Audio tab.
- Modern player layout custom action buttons scale consistently with built-in controls.
- Shader peek upscale chip no longer covers top-right player buttons when smart skip is absent.
</code_context>
<issue_to_address>
**Release notes omit audio fix**
When this user-visible behavior change is prepared for release, `CHANGELOG.md` is not updated, so the user-facing release notes omit this audio-tab fix.
Add the audio-tab fix to `CHANGELOG.md` alongside the unreleased note.
</issue_to_address>Sourcery assessment
Approval pending. 9 findings to address first.
Blocking findings: app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:163, app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:269, app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:500, app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:167, app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:394, and 4 more
| Log.e(TAG, "Error scanning MediaStore for audio", e) | ||
| scanAudioFromMediaStore(context, tracksByPath) | ||
| scanAudioFromMediaStoreFiles(context, tracksByPath) | ||
| if (tracksByPath.isEmpty()) { |
There was a problem hiding this comment.
🟡 Medium · Unindexed audio stays missing
When mediaStore contains at least one audio track and another supported audio file is absent from its queried tables, scanAudio runs scanAudioFromFileSystem only when tracksByPath is empty, so any indexed track suppresses the fallback and the unindexed file stays out of the Audio tab.
Run scanAudioFromFileSystem alongside the MediaStore scans and deduplicate the resulting tracks.
Also at UNRELEASED.md:21.
Prompt for AI agents
In `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt` at line 163:
**Unindexed audio stays missing**
When mediaStore contains at least one audio track and another supported audio file is absent from its queried tables, `scanAudio` runs `scanAudioFromFileSystem` only when `tracksByPath` is empty, so any indexed track suppresses the fallback and the unindexed file stays out of the Audio tab.
Run `scanAudioFromFileSystem` alongside the MediaStore scans and deduplicate the resulting tracks.
Also at `UNRELEASED.md:21`.From AGENTS.md L224-225:
- Every claim must be true and, where possible, measurable. Never say
"faster" without saying what got faster.| cursor.use { | ||
| val columns = TrackColumns(it) | ||
| while (it.moveToNext()) { | ||
| val track = buildTrack( |
There was a problem hiding this comment.
🟡 Medium · Audio library fails to load
When the files-table provider returns a cursor but throws while advancing it, reading a row, or building a track, scanAudioFromMediaStoreFiles lets the exception escape, so scanAudio stops before it can return collected tracks or run the filesystem fallback, and the Audio library fails to load.
Catch errors while consuming the files-table cursor so the scan can retain available tracks and continue.
Prompt for AI agents
In `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt` at lines 266-269:
**Audio library fails to load**
When the files-table provider returns a cursor but throws while advancing it, reading a row, or building a track, `scanAudioFromMediaStoreFiles` lets the exception escape, so `scanAudio` stops before it can return collected tracks or run the filesystem fallback, and the Audio library fails to load.
Catch errors while consuming the files-table cursor so the scan can retain available tracks and continue.| val album = file.parentFile?.name?.takeIf { it.isNotBlank() } ?: "Unknown Album" | ||
|
|
||
| return LocalAudioTrack( | ||
| id = file.absolutePath.hashCode().toLong(), |
There was a problem hiding this comment.
🟡 Medium · Audio list keys collide
When the filesystem fallback finds two distinct files whose absolute paths have the same Java string hash, buildTrackFromFile uses the path hash as id, so both tracks receive the same lazy-list key and Compose throws instead of displaying them.
Assign fallback tracks IDs that are unique for distinct files rather than using only the path hash.
Prompt for AI agents
In `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt` at line 500:
**Audio list keys collide**
When the filesystem fallback finds two distinct files whose absolute paths have the same Java string hash, `buildTrackFromFile` uses the path hash as `id`, so both tracks receive the same lazy-list key and Compose throws instead of displaying them.
Assign fallback tracks IDs that are unique for distinct files rather than using only the path hash.| scanAudioFromFileSystem(context, tracksByPath) | ||
| } | ||
|
|
||
| val tracks = enrichMissingDurations(context, tracksByPath.values.toList()) |
There was a problem hiding this comment.
🟡 Medium · Older scans overwrite newer library
When two refreshes overlap, a newer one finishes before an older scan, the older AudioRepository.refresh() finishes last and replaces _libraryData with its earlier scan result, even after a newer refresh has already published current tracks; the Audio tab then shows stale library contents until another refresh.
Serialize audio scans or publish results only when their refresh generation is still current.
Prompt for AI agents
In `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt` at line 167:
**Older scans overwrite newer library**
When two refreshes overlap, a newer one finishes before an older scan, the older `AudioRepository.refresh()` finishes last and replaces `_libraryData` with its earlier scan result, even after a newer refresh has already published current tracks; the Audio tab then shows stale library contents until another refresh.
Serialize audio scans or publish results only when their refresh generation is still current.| } | ||
|
|
||
| private fun trackKey(track: LocalAudioTrack): String = | ||
| track.path.ifBlank { "${track.displayName}|${track.size}" } |
There was a problem hiding this comment.
🟡 Medium · Distinct tracks are discarded
When two distinct tracks have blank paths and identical display names and sizes, trackKey gives both tracks the same displayName|size key, so putIfAbsent discards the later track and the library omits it.
Use a key that distinguishes distinct pathless tracks.
Prompt for AI agents
In `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt` at line 394:
**Distinct tracks are discarded**
When two distinct tracks have blank paths and identical display names and sizes, `trackKey` gives both tracks the same `displayName|size` key, so `putIfAbsent` discards the later track and the library omits it.
Use a key that distinguishes distinct pathless tracks.| size = size, | ||
| sizeFormatted = VideoScanUtils.formatFileSize(size), | ||
| path = file.absolutePath, | ||
| uri = Uri.fromFile(file), |
There was a problem hiding this comment.
🟡 Medium · Fallback durations stay zero
When a filesystem-only track has no indexed duration, enrichMissingDurations passes the file:// URI from buildTrackFromFile to MediaInfoOps.extractBasicMetadata, which opens it with ContentResolver.openFileDescriptor; that lookup fails and the track keeps duration 0.
Read filesystem-only track metadata from the file path or another URI form supported by the metadata reader.
Also at app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:567.
Prompt for AI agents
In `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt` at line 515:
**Fallback durations stay zero**
When a filesystem-only track has no indexed duration, `enrichMissingDurations` passes the `file://` URI from `buildTrackFromFile` to `MediaInfoOps.extractBasicMetadata`, which opens it with `ContentResolver.openFileDescriptor`; that lookup fails and the track keeps duration `0`.
Read filesystem-only track metadata from the file path or another URI form supported by the metadata reader.
Also at `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:567`.| context.contentResolver.query( | ||
| FILES_URI, | ||
| projection, | ||
| AUDIO_FILES_SELECTION, |
There was a problem hiding this comment.
🟡 Medium · Hidden audio rows enter library
When MediaStore.Files contains a supported audio row under a hidden, skipped, or .nomedia folder, queryFilesTable selects matching MIME types and extensions without applying the hidden-folder or .nomedia exclusions used by the filesystem walk, so matching rows already present in MediaStore.Files are added to the visible library.
Apply the same exclusion policy to files-table results before adding tracks.
Prompt for AI agents
In `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt` at line 287:
**Hidden audio rows enter library**
When `MediaStore.Files` contains a supported audio row under a hidden, skipped, or `.nomedia` folder, `queryFilesTable` selects matching MIME types and extensions without applying the hidden-folder or `.nomedia` exclusions used by the filesystem walk, so matching rows already present in `MediaStore.Files` are added to the visible library.
Apply the same exclusion policy to files-table results before adding tracks.| return fileSystemProbeResult | ||
| } | ||
|
|
||
| val found = audioSearchRoots(context).any { containsAudioFile(it, 0) } |
There was a problem hiding this comment.
🟡 Medium · Hidden audio gets exposed
When a common search-root directory such as Music or Downloads contains .nomedia and audio files directly inside it, containsAudioFile and collectAudioFiles apply shouldSkipFolder only to child directories, not to the roots passed in; audio directly inside a root containing .nomedia is therefore reported by the probe and added to the Audio tab.
Check whether each search root should be skipped before probing or collecting its contents.
Also at app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:438.
Prompt for AI agents
In `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt` at line 406:
**Hidden audio gets exposed**
When a common search-root directory such as Music or Downloads contains `.nomedia` and audio files directly inside it, `containsAudioFile` and `collectAudioFiles` apply `shouldSkipFolder` only to child directories, not to the roots passed in; audio directly inside a root containing `.nomedia` is therefore reported by the probe and added to the Audio tab.
Check whether each search root should be skipped before probing or collecting its contents.
Also at `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:438`.| } | ||
|
|
||
| // Then the whole volume, so audio in custom folders is not missed. | ||
| paths.add(primaryStorage.absolutePath) |
There was a problem hiding this comment.
🟡 Medium · Audio probe walks the whole volume
When mediaStore has no audio rows and the common directories do not contain an audio file, audioSearchRoots includes the primary storage root, and containsAudioFile recursively traverses its directories. When MediaStore has no audio and the early directories contain none, the presence check enumerates the entire accessible volume up to the depth limit, delaying the Audio tab decision on devices with large storage trees.
Bound the probe by elapsed time or number of visited entries, or restrict it to likely media locations instead of recursively walking the whole volume.
Also at app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:423.
Prompt for AI agents
In `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt` at line 486:
**Audio probe walks the whole volume**
When mediaStore has no audio rows and the common directories do not contain an audio file, `audioSearchRoots` includes the primary storage root, and `containsAudioFile` recursively traverses its directories. When MediaStore has no audio and the early directories contain none, the presence check enumerates the entire accessible volume up to the depth limit, delaying the Audio tab decision on devices with large storage trees.
Bound the probe by elapsed time or number of visited entries, or restrict it to likely media locations instead of recursively walking the whole volume.
Also at `app/src/main/java/app/aryan447/mpvium/domain/audio/AudioScanUtils.kt:423`.|
|
||
| ### Fixed | ||
|
|
||
| - Audio files Android's media scanner skips, including `.opus` downloads, now appear in the Audio tab. |
There was a problem hiding this comment.
⚪ Low · Release notes omit audio fix
When this user-visible behavior change is prepared for release, CHANGELOG.md is not updated, so the user-facing release notes omit this audio-tab fix.
Add the audio-tab fix to CHANGELOG.md alongside the unreleased note.
Prompt for AI agents
In `UNRELEASED.md` at line 21:
**Release notes omit audio fix**
When this user-visible behavior change is prepared for release, `CHANGELOG.md` is not updated, so the user-facing release notes omit this audio-tab fix.
Add the audio-tab fix to `CHANGELOG.md` alongside the unreleased note.From AGENTS.md L229:
- Update both files in the same change that alters user-visible behavior.
Summary
MediaStore.Audioalone. It now merges the audio table, the files table, and a bounded filesystem fallback, deduplicated by path..opusdownloads under folders likeDownload/YTDLnis/Audio— are detected by MIME type and every supported audio extension.hasAudio()uses the same fallback chain, so the tab is no longer hidden when the media database reports zero audio rows.Closes #194.
Before / After
.opuslibrary only inMediaStore.FilesUnknown Albumwith0sdurationVerification
./gradlew :app:compileStandardDebugKotlin --offline./gradlew :app:testStandardDebugUnitTest --offlinegit diff --checkNo performance numbers are claimed; scan timing was not measured.
Changelog
UNRELEASED.md→ Fixed: "Audio files Android's media scanner skips, including.opusdownloads, now appear in the Audio tab."Risks
Summary by Sourcery
Make audio discovery resilient to incomplete media indexing so supported files consistently appear in the Audio tab.
New Features:
.opus, in the Audio tab.Bug Fixes:
Enhancements:
Documentation:
Chores: