mirror of
https://github.com/FluxaMedia/fluxa.git
synced 2026-08-18 21:18:32 +00:00
Deactivate torrents when Android playback stops
This commit is contained in:
parent
fd0d3775a8
commit
bc9d97ed8a
1 changed files with 10 additions and 2 deletions
|
|
@ -50,6 +50,7 @@ class TorrentStreamManager private constructor() {
|
|||
@Volatile private var pendingSettings = defaultSettings()
|
||||
@Volatile private var appContext: Context? = null
|
||||
@Volatile private var engine: TorrentServerEngine? = null
|
||||
@Volatile private var activeTorrentLink: String? = null
|
||||
|
||||
private val _status = MutableStateFlow(TorrentStreamStatus())
|
||||
val status: StateFlow<TorrentStreamStatus> = _status.asStateFlow()
|
||||
|
|
@ -65,8 +66,8 @@ class TorrentStreamManager private constructor() {
|
|||
}
|
||||
}
|
||||
|
||||
fun configurePreferences(speedPreset: String?) {
|
||||
val newSettings = TorrentSettings(preloadSize = speedPreset.toPreloadSizeMb())
|
||||
fun configurePreferences(speedPreset: String?, cacheLimitMb: Long? = null) {
|
||||
val newSettings = TorrentSettings(preloadSize = speedPreset.toPreloadSizeMb(), cacheLimitMb = cacheLimitMb)
|
||||
if (newSettings == pendingSettings) return
|
||||
pendingSettings = newSettings
|
||||
scope.launch {
|
||||
|
|
@ -155,6 +156,7 @@ class TorrentStreamManager private constructor() {
|
|||
}.onFailure { Log.w(TAG, "background addTorrent failed", it) }
|
||||
}
|
||||
startStatusPolling(plan.normalizedLink, videoId)
|
||||
activeTorrentLink = plan.normalizedLink
|
||||
callback(TorrentStreamResult.Success(plan.streamUrl))
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Torrent stream failed", e)
|
||||
|
|
@ -167,6 +169,12 @@ class TorrentStreamManager private constructor() {
|
|||
statusJob?.cancel()
|
||||
statusJob = null
|
||||
_status.value = TorrentStreamStatus()
|
||||
activeTorrentLink?.let { link ->
|
||||
scope.launch {
|
||||
runCatching { api.removeTorrent(TorrentRequest(action = "deactivate", link = link)) }
|
||||
}
|
||||
}
|
||||
activeTorrentLink = null
|
||||
}
|
||||
|
||||
fun shutdown() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue