Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
94c75e5
refactor(player): move the now playing slots out of the full player c…
A-EDev Nov 16, 2026
efbb877
fix(downloads): stop asking for All files access on the first download
A-EDev Nov 16, 2026
6b306eb
refactor(crossfade): move the skip hold out of the crossfader
A-EDev Nov 16, 2026
9171d36
perf(player): preload the next song in the music player
A-EDev Nov 16, 2026
ceac650
fix(player): keep the wavy seek bar's wave behind its thumb
A-EDev Nov 16, 2026
90477ad
fix(lyrics): drop the press box from lyric lines
A-EDev Nov 16, 2026
b2d3459
feat(lyrics): count repeated lines in the one-line lyrics
A-EDev Nov 16, 2026
65b9ef4
feat(player): show lyrics over the immersive cover
A-EDev Nov 16, 2026
0569d72
fix(sync): hash collections line by line instead of one joined string
A-EDev Nov 16, 2026
0aeab38
fix(crossfade): fade on skip even while the next song is still loading
A-EDev Nov 16, 2026
f50e55e
feat(downloads): find earlier downloads in the folder you picked
A-EDev Nov 16, 2026
62517f0
perf(sync): skip hashing received collections the server sync never c…
A-EDev Nov 16, 2026
c44693c
Merge branch 'fix/wavy-seek-thumb' into merge/issues-2150-1278
A-EDev Nov 16, 2026
1358aea
Merge branch 'fix/lyric-press-box' into merge/issues-2150-1278
A-EDev Nov 16, 2026
875e369
Merge branch 'feat/lyric-repeat-count' into merge/issues-2150-1278
A-EDev Nov 16, 2026
c8c2c3b
Merge branch 'perf/sync-received-key-hash' into merge/issues-2150-1278
A-EDev Nov 16, 2026
3684de4
Merge branch 'fix/crossfade-skip-fade-while-loading' into merge/issue…
A-EDev Nov 16, 2026
38db2ee
Merge branch 'perf/music-preload-next' into merge/issues-2150-1278
A-EDev Nov 16, 2026
3c26784
Merge branch 'fix/downloads-no-all-files-prompt' into merge/issues-21…
A-EDev Nov 16, 2026
bd14c14
Merge branch 'feat/downloads-find-in-picked-folder' into merge/issues…
A-EDev Nov 16, 2026
ab0b374
Merge branch 'feat/immersive-lyrics-in-place' into merge/issues-2150-…
A-EDev Nov 16, 2026
c044dda
feat(player): make lyrics over the immersive cover an opt-in switch
A-EDev Nov 16, 2026
edbce52
Merge branch 'feat/immersive-lyrics-in-place' into merge/issues-2150-…
A-EDev Nov 16, 2026
5101186
test(player): count the lyrics on the cover preference key
A-EDev Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Fixed
- After reinstalling, Flow can find your downloads again in the folder you choose (#1255)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## New
- In Immersive, lyrics can show in the player over the cover, with a full-screen button; turn on Lyrics on the cover in Player Appearance (#1278)
2 changes: 2 additions & 0 deletions .github/nightly-notes/2026-11-16-feat-lyric-repeat-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Improved
- Repeated lyric lines show ×2, ×3 in the mini player and lock screen (#2148)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Fixed
- Fade when you skip now starts right away on Next and Previous (#2076)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Improved
- Downloads no longer ask for access to all files (#1255)
2 changes: 2 additions & 0 deletions .github/nightly-notes/2026-11-16-fix-lyric-press-box.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Fixed
- Tapping a lyric line no longer draws a box around it (#2147)
2 changes: 2 additions & 0 deletions .github/nightly-notes/2026-11-16-fix-sync-streamed-hash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Fixed
- Syncing a large history no longer crashes Flow (#2145)
2 changes: 2 additions & 0 deletions .github/nightly-notes/2026-11-16-fix-wavy-seek-thumb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Fixed
- The wavy seek bar no longer pokes out past its thumb at the start of a song (#2150)
2 changes: 2 additions & 0 deletions .github/nightly-notes/2026-11-16-perf-music-preload-next.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
## Improved
- The next song starts faster when you skip (#2076)
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class PlayerPreferences(
val LYRICS_SHOW_ROMANIZATION = booleanPreferencesKey("lyrics_show_romanization")
val LYRICS_ON_LOCK_SCREEN = booleanPreferencesKey("lyrics_on_lock_screen")
val LYRICS_IN_MINI_PLAYER = booleanPreferencesKey("lyrics_in_mini_player")
val IMMERSIVE_LYRICS_ON_COVER = booleanPreferencesKey("immersive_lyrics_on_cover")
val LYRICS_ON_DEMAND = booleanPreferencesKey("lyrics_on_demand")
val LYRICS_ON_LOCK_SCREEN_DELAY_MS = intPreferencesKey("lyrics_on_lock_screen_delay_ms")
val LYRICS_SPONSORBLOCK_TIMING = booleanPreferencesKey("lyrics_sponsorblock_timing")
Expand Down Expand Up @@ -4744,6 +4745,14 @@ class PlayerPreferences(
context.playerPreferencesDataStore.edit { it[Keys.LYRICS_IN_MINI_PLAYER] = enabled }
}

/** Whether the immersive player's lyrics button shows lyrics over the cover instead of opening the sheet. */
val immersiveLyricsOnCover: Flow<Boolean> =
context.playerPreferencesDataStore.data.map { it[Keys.IMMERSIVE_LYRICS_ON_COVER] ?: false }

suspend fun setImmersiveLyricsOnCover(enabled: Boolean) {
context.playerPreferencesDataStore.edit { it[Keys.IMMERSIVE_LYRICS_ON_COVER] = enabled }
}

/** Whether lyrics are looked up only when the player or its lyrics open, or for lock screen lyrics. */
val lyricsOnDemand: Flow<Boolean> =
context.playerPreferencesDataStore.data.map { it[Keys.LYRICS_ON_DEMAND] ?: false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.github.aedev.flow.data.video.VideoDownloadManager.Companion.VIDEO_DIR
import io.github.aedev.flow.data.video.downloader.tags.DownloadTagReader
import io.github.aedev.flow.data.video.storage.DownloadCovers
import io.github.aedev.flow.data.video.storage.DownloadFiles
import io.github.aedev.flow.data.video.storage.DownloadTree
import io.github.aedev.flow.data.video.storage.StorageAccess
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -44,20 +45,27 @@ class DownloadRecoveryScanner
private val preferences: PlayerPreferences,
private val tagReader: DownloadTagReader,
) {
private data class Reach(
val access: StorageAccess,
val trees: Set<String>,
)

/** What the last scan in this process could read. */
@Volatile
private var scannedWith: StorageAccess? = null
private var scannedWith: Reach? = null

/**
* Whether a scan could find something the last one couldn't: none has run yet, or Flow may now
* read more shared storage, as after the viewer grants media access.
* read more shared storage, as after the viewer grants media access or picks a folder again.
*/
fun needsScan(): Boolean = scannedWith != StorageAccess.read(context)
fun needsScan(): Boolean = scannedWith != reach()

private fun reach() = Reach(StorageAccess.read(context), DownloadFiles.grantedTrees(context))

/** Records every new file it finds and returns how many that was. */
suspend fun scanAndRecoverDownloads(): Int =
withContext(Dispatchers.IO) {
scannedWith = StorageAccess.read(context)
scannedWith = reach()
var recovered = 0
try {
val chosenFolders = chosenFolders()
Expand Down Expand Up @@ -85,6 +93,7 @@ class DownloadRecoveryScanner
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) recovered += scanViaMediaStore(roots, exportedPaths)
recovered += scanPickedFolders(exportedPaths)
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Expand Down Expand Up @@ -154,8 +163,28 @@ class DownloadRecoveryScanner
recovered
}

/**
* The picked folders read through their grant, which needs no media access: a reinstalled Flow
* owns none of the files an earlier install saved, so the media index hides them from it.
*/
private suspend fun scanPickedFolders(exportedPaths: Set<String>): Int {
val granted = DownloadFiles.grantedTrees(context)
var recovered = 0
for (tree in chosenLocations().mapNotNull { it.treeUri }.distinct().filter { it in granted }) {
for (file in DownloadTree.files(context, tree, COLLECTION_DEPTH)) {
if (!RecoveredDownload.isMedia(file.name)) continue
val path = DownloadFiles.documentPath(file.uri)
if (path != null && !isNewFile(path, exportedPaths)) continue
if (recoverIfNew(file.uri, file.name, file.sizeBytes, file.modifiedAt, durationMs = null, exportedPaths)) recovered++
}
}
return recovered
}

private suspend fun chosenLocations() = listOf(preferences.downloadLocation.first(), preferences.musicDownloadLocation.first())

private suspend fun chosenFolders(): List<String> =
listOf(preferences.downloadLocation.first(), preferences.musicDownloadLocation.first())
chosenLocations()
.mapNotNull { location -> location.path?.takeIf { it.isNotBlank() } ?: location.treeUri?.let(DownloadFiles::treePath) }
.distinct()

Expand Down Expand Up @@ -186,7 +215,7 @@ class DownloadRecoveryScanner
exportedPaths: Set<String>,
): Boolean {
if (!isNewFile(filePath, exportedPaths)) return false
val embedded = tagReader.read(Uri.fromFile(File(filePath)))
val embedded = tagReader.read(uriOf(filePath))
val tags = embedded?.flow
val sourceUrl = embedded?.comment
val videoId = RecoveredDownload.idFor(filePath, tags, sourceUrl)
Expand Down Expand Up @@ -229,7 +258,7 @@ class DownloadRecoveryScanner
): Probe {
val retriever = MediaMetadataRetriever()
return try {
retriever.setDataSource(filePath)
retriever.setDataSource(context, uriOf(filePath))
val duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)?.toLongOrNull() ?: 0L
val frame =
if (wantsFrame) {
Expand Down Expand Up @@ -262,6 +291,8 @@ class DownloadRecoveryScanner
}
}

private fun uriOf(path: String): Uri = if (DownloadFiles.isDocument(path)) Uri.parse(path) else Uri.fromFile(File(path))

private companion object {
const val TAG = "DownloadRecoveryScanner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ package io.github.aedev.flow.data.video
import android.content.ContentUris
import android.content.ContentValues
import android.content.Context
import android.content.Intent
import android.media.MediaScannerConnection
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.MediaStore
import android.provider.Settings
import android.util.Log
import dagger.hilt.android.qualifiers.ApplicationContext
import io.github.aedev.flow.data.local.PlayerPreferences
Expand Down Expand Up @@ -141,35 +138,6 @@ class VideoDownloadManager
false
}

/**
* Request All Files Access permission (MANAGE_EXTERNAL_STORAGE) on Android 11+.
* This opens the system settings page where the user can grant the permission.
* Call this before starting downloads to ensure files go to public storage.
*/
fun requestAllFilesAccess(context: Context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !Environment.isExternalStorageManager()) {
try {
val intent =
Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION).apply {
data = Uri.parse("package:${context.packageName}")
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(intent)
} catch (e: Exception) {
Log.w(TAG, "Failed to open MANAGE_ALL_FILES_ACCESS settings, trying fallback", e)
try {
val intent =
Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
context.startActivity(intent)
} catch (e2: Exception) {
Log.e(TAG, "Could not open file access settings", e2)
}
}
}
}

/**
* Tell the Android system to scan the newly downloaded file.
* This adds the file into the system's MediaStore index so it's instantly
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.github.aedev.flow.data.video.storage

/**
* The files in a picked folder and in the folders below it down to [maxDepth] levels, as
* [children] lists them. Hidden entries are skipped, which leaves out the system's `.trashed-` and
* `.pending-` files. A provider can be slow and a folder huge, so the walk stops after [limit]
* listed documents.
*/
internal fun filesInTree(
rootId: String,
maxDepth: Int,
limit: Int,
children: (String) -> List<TreeDocument>,
): List<TreeDocument> {
val files = mutableListOf<TreeDocument>()
var listed = 0
val pending = ArrayDeque(listOf(rootId to 1))
while (pending.isNotEmpty() && listed < limit) {
val (folderId, depth) = pending.removeFirst()
for (document in children(folderId)) {
if (++listed > limit) break
if (document.name.startsWith('.')) continue
when {
!document.isFolder -> files += document
depth < maxDepth -> pending += document.id to depth + 1
}
}
}
return files
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ object DownloadFiles {
return context.contentResolver.persistedUriPermissions.any { it.uri == uri && it.isWritePermission }
}

/** The picked folders Flow may still write to. */
fun grantedTrees(context: Context): Set<String> =
context.contentResolver.persistedUriPermissions
.filter { it.isWritePermission }
.mapTo(mutableSetOf()) { it.uri.toString() }

fun releaseTree(
context: Context,
treeUri: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ fun resolveDownloadDestination(
return DownloadDestination(fallback, fellBack = chosen.isSet)
}

/**
* The picked folder Flow can no longer open, as after a reinstall: the saved location comes back
* with the settings backup, but Android drops the folder's grant. Null when every picked folder can
* still be used, or when All files access reaches the folder through its path anyway.
*/
fun lostDownloadTree(
locations: List<DownloadLocation>,
grantedTrees: Set<String>,
hasAllFilesAccess: Boolean,
): String? =
locations
.firstOrNull { location ->
val tree = location.treeUri
!tree.isNullOrBlank() && tree !in grantedTrees && !(hasAllFilesAccess && !location.path.isNullOrBlank())
}?.treeUri

/**
* The file-system path behind a storage provider document id such as `primary:Movies/Flow`, or
* null when the id does not name a place on a storage volume.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package io.github.aedev.flow.data.video.storage

import android.content.Context
import android.net.Uri
import android.provider.DocumentsContract
import android.provider.DocumentsContract.Document
import android.util.Log

/** A file or folder inside a picked folder, as the storage provider lists it. */
internal data class TreeDocument(
val id: String,
val name: String,
val isFolder: Boolean,
val sizeBytes: Long = 0L,
val modifiedAt: Long = 0L,
)

/** A file found in a picked folder: its `content://` document and what the provider says about it. */
internal data class TreeFile(
val uri: String,
val name: String,
val sizeBytes: Long,
val modifiedAt: Long,
)

/** Lists picked download folders through their tree grant, which is how Flow reads them without media access. */
internal object DownloadTree {
private const val TAG = "DownloadTree"
private const val MAX_DOCUMENTS = 20_000

private val Columns =
arrayOf(
Document.COLUMN_DOCUMENT_ID,
Document.COLUMN_DISPLAY_NAME,
Document.COLUMN_MIME_TYPE,
Document.COLUMN_SIZE,
Document.COLUMN_LAST_MODIFIED,
)

/** The files in [treeUri] and in the folders [maxDepth] levels below it; empty when it can't be read. */
fun files(
context: Context,
treeUri: String,
maxDepth: Int,
): List<TreeFile> {
val tree = Uri.parse(treeUri)
val rootId = runCatching { DocumentsContract.getTreeDocumentId(tree) }.getOrNull() ?: return emptyList()
return filesInTree(rootId, maxDepth, MAX_DOCUMENTS) { children(context, tree, it) }
.map { TreeFile(DocumentsContract.buildDocumentUriUsingTree(tree, it.id).toString(), it.name, it.sizeBytes, it.modifiedAt) }
}

private fun children(
context: Context,
tree: Uri,
folderId: String,
): List<TreeDocument> =
runCatching {
val uri = DocumentsContract.buildChildDocumentsUriUsingTree(tree, folderId)
context.contentResolver
.query(uri, Columns, null, null, null)
?.use { cursor ->
buildList {
while (cursor.moveToNext()) {
val id = cursor.getString(0) ?: continue
add(
TreeDocument(
id = id,
name = cursor.getString(1).orEmpty(),
isFolder = cursor.getString(2) == Document.MIME_TYPE_DIR,
sizeBytes = if (cursor.isNull(3)) 0L else cursor.getLong(3),
modifiedAt = if (cursor.isNull(4)) 0L else cursor.getLong(4),
),
)
}
}
}.orEmpty()
}.onFailure { Log.w(TAG, "Could not list $folderId in $tree", it) }
.getOrDefault(emptyList())
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ internal object CrossfadePolicy {
/** With no old song to blend with, the next one still comes in over this long instead of at full volume. */
const val QUICK_FADE_IN_MS = 400L

/** A skipped-to song not playing this long after the old one moved to its tail is late, and the old one fades out anyway. */
const val LATE_NEXT_SONG_MS = 1_000L

/** A lined-up tail takes over no sooner than this before the fade, so a short fade still ends with the song. */
private const val HAND_OFF_EARLY_MS = 500L

Expand Down Expand Up @@ -234,6 +237,15 @@ internal object CrossfadePolicy {
return minOf(fadeMs.coerceIn(0L, MAX_MS), leftOnClock).coerceAtLeast(1L)
}

/** How long a skipped-to song that came late fades in: quickly, since the old song is already fading or gone. */
fun lateFadeInClockMs(skipClockMs: Long): Long = minOf(QUICK_FADE_IN_MS, skipClockMs).coerceAtLeast(1L)

/** A song's length from its metadata, or the player's own when the metadata has none; null while neither knows it. */
fun knownDurationMs(
metadataMs: Long?,
playerMs: Long,
): Long? = metadataMs ?: playerMs.takeIf { it > 0L }

/** How long a skip overlaps the two songs on the clock: the chosen fade, or just [SKIP_BLEND_MS] without one. */
fun skipClockMs(
settings: Settings,
Expand Down
Loading
Loading