mirror of
https://github.com/kalarina-bit/Fogwave.git
synced 2026-11-22 08:06:09 +00:00
Compare commits
5
Commits
v1.0.12
...
5561754a71
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5561754a71 | ||
|
|
f84df8b21e | ||
|
|
197ac2784c | ||
|
|
237be98cf0 | ||
|
|
91e5467d11 |
@@ -0,0 +1,27 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Something doesn't work as expected
|
||||
title: "[Bug] "
|
||||
---
|
||||
|
||||
**What happened**
|
||||
|
||||
|
||||
**Steps to reproduce**
|
||||
|
||||
1.
|
||||
2.
|
||||
3.
|
||||
|
||||
**What you expected**
|
||||
|
||||
|
||||
**Environment**
|
||||
|
||||
- App version:
|
||||
- Installed from: Gitea / GitHub / F-Droid / Google Play
|
||||
- Device and Android version:
|
||||
- Station (if related):
|
||||
|
||||
**Screenshots or logs** (optional)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
blank_issues_enabled: true
|
||||
contact_links:
|
||||
- name: Main repository on git.skysparkle.cc
|
||||
url: https://git.skysparkle.cc/kalarina/Fogwave
|
||||
about: This GitHub repository is a mirror. Issues are welcome here and on Gitea.
|
||||
@@ -0,0 +1,18 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea that fits the app
|
||||
title: "[Feature] "
|
||||
---
|
||||
|
||||
<!-- Please check the "Out of scope" list in CONTRIBUTING.md before opening this. -->
|
||||
|
||||
**What problem does this solve**
|
||||
|
||||
|
||||
**Proposed solution**
|
||||
|
||||
|
||||
**Alternatives you considered**
|
||||
|
||||
|
||||
- [ ] I'd like to implement this myself
|
||||
@@ -0,0 +1,15 @@
|
||||
---
|
||||
name: Station request
|
||||
about: Suggest a Lithuanian radio station
|
||||
title: "[Station] "
|
||||
---
|
||||
|
||||
<!-- Only Lithuanian stations with an official public stream are accepted. -->
|
||||
|
||||
- Station name:
|
||||
- Official website:
|
||||
- Stream URL:
|
||||
- Genre:
|
||||
|
||||
- [ ] The station is Lithuanian
|
||||
- [ ] The stream is official and public
|
||||
@@ -0,0 +1,12 @@
|
||||
---
|
||||
name: Translation fix
|
||||
about: Report a wrong or awkward translation
|
||||
title: "[Translation] "
|
||||
---
|
||||
|
||||
<!-- Supported languages: English, Russian, German, Japanese, Lithuanian, Chinese. New languages are not accepted. -->
|
||||
|
||||
- Language:
|
||||
- Screen or place in the app:
|
||||
- Current text:
|
||||
- Suggested text:
|
||||
@@ -0,0 +1,16 @@
|
||||
## What does this change
|
||||
|
||||
|
||||
## Related issue
|
||||
|
||||
Closes #
|
||||
|
||||
## Checklist
|
||||
|
||||
- [ ] Discussed in an issue first (not needed for small fixes)
|
||||
- [ ] `./gradlew assembleDebug` builds
|
||||
- [ ] Tested on a device or emulator (Android version: )
|
||||
- [ ] No ads, analytics, trackers or Google Play Services / Firebase dependencies
|
||||
- [ ] New strings added to `values/strings.xml` (missing translations noted below)
|
||||
- [ ] Screenshots added for UI changes
|
||||
- [ ] I agree that my contribution is licensed under GPL-3.0-only
|
||||
@@ -13,8 +13,8 @@ android {
|
||||
applicationId = "cc.skysparkle.fogwave"
|
||||
minSdk = 24
|
||||
targetSdk = 36
|
||||
versionCode = 12
|
||||
versionName = "1.0.12"
|
||||
versionCode = 13
|
||||
versionName = "1.0.13"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ data class AudioEffectsState(
|
||||
val dynamicsProcessingEnabled: Boolean = false
|
||||
)
|
||||
|
||||
// Effect parameters are cached here: every getter on an AudioEffect is a call into audioserver,
|
||||
// and the state is rebuilt on every frame while an equalizer slider is dragged.
|
||||
class AudioEffectsEngine(context: Context, audioSessionId: Int) {
|
||||
private val prefs: SharedPreferences =
|
||||
context.applicationContext.getSharedPreferences("fogwave_audio_effects", Context.MODE_PRIVATE)
|
||||
@@ -42,37 +44,53 @@ class AudioEffectsEngine(context: Context, audioSessionId: Int) {
|
||||
private var loudnessEnhancer: LoudnessEnhancer? = null
|
||||
private var dynamicsProcessing: DynamicsProcessing? = null
|
||||
|
||||
private val presetNames = mutableListOf<String>()
|
||||
private var presetNames: List<String> = emptyList()
|
||||
private var centerFreqsHz = IntArray(0)
|
||||
private var bandLevels = IntArray(0)
|
||||
private var minBandLevel = 0
|
||||
private var maxBandLevel = 0
|
||||
|
||||
private var equalizerEnabled = prefs.getBoolean(KEY_EQ_ENABLED, false)
|
||||
private var loudnessEnabled = prefs.getBoolean(KEY_LOUDNESS_ENABLED, false)
|
||||
private var loudnessGain = prefs.getInt(KEY_LOUDNESS_GAIN, 0).coerceIn(0, MAX_LOUDNESS_GAIN)
|
||||
private var dynamicsEnabled = prefs.getBoolean(KEY_DYNAMICS_ENABLED, false)
|
||||
|
||||
init {
|
||||
try {
|
||||
equalizer = Equalizer(0, audioSessionId).apply {
|
||||
for (p in 0 until numberOfPresets) {
|
||||
presetNames.add(getPresetName(p.toShort()))
|
||||
}
|
||||
presetNames = (0 until numberOfPresets).map { getPresetName(it.toShort()) }
|
||||
|
||||
val bandCount = numberOfBands.toInt()
|
||||
centerFreqsHz = IntArray(bandCount) { getCenterFreq(it.toShort()) / 1000 }
|
||||
val range = bandLevelRange
|
||||
minBandLevel = range[0].toInt()
|
||||
maxBandLevel = range[1].toInt()
|
||||
|
||||
val preset = currentPresetIndex
|
||||
if (preset in 0 until numberOfPresets) {
|
||||
usePreset(preset.toShort())
|
||||
} else {
|
||||
for (b in 0 until numberOfBands) {
|
||||
for (b in 0 until bandCount) {
|
||||
val saved = prefs.getInt(KEY_BAND_PREFIX + b, Int.MIN_VALUE)
|
||||
if (saved != Int.MIN_VALUE) setBandLevel(b.toShort(), saved.toShort())
|
||||
}
|
||||
}
|
||||
enabled = prefs.getBoolean(KEY_EQ_ENABLED, false)
|
||||
bandLevels = IntArray(bandCount) { getBandLevel(it.toShort()).toInt() }
|
||||
enabled = equalizerEnabled
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Equalizer unavailable", e)
|
||||
equalizer = null
|
||||
}
|
||||
|
||||
try {
|
||||
loudnessEnhancer = LoudnessEnhancer(audioSessionId).apply {
|
||||
setTargetGain(prefs.getInt(KEY_LOUDNESS_GAIN, 0))
|
||||
enabled = prefs.getBoolean(KEY_LOUDNESS_ENABLED, false)
|
||||
setTargetGain(loudnessGain)
|
||||
enabled = loudnessEnabled
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "LoudnessEnhancer unavailable", e)
|
||||
loudnessEnhancer = null
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
@@ -134,94 +152,103 @@ class AudioEffectsEngine(context: Context, audioSessionId: Int) {
|
||||
dp.setLimiterByChannelIndex(ch, limiter)
|
||||
}
|
||||
|
||||
dp.enabled = prefs.getBoolean(KEY_DYNAMICS_ENABLED, false)
|
||||
dp.enabled = dynamicsEnabled
|
||||
return dp
|
||||
}
|
||||
|
||||
fun currentState(): AudioEffectsState {
|
||||
val eq = equalizer
|
||||
val bands = if (eq != null) {
|
||||
(0 until eq.numberOfBands).map { i ->
|
||||
val idx = i.toShort()
|
||||
val range = eq.bandLevelRange
|
||||
val eqAvailable = equalizer != null
|
||||
val bands = if (eqAvailable) {
|
||||
bandLevels.indices.map { i ->
|
||||
EqualizerBand(
|
||||
index = i,
|
||||
centerFreqHz = eq.getCenterFreq(idx) / 1000,
|
||||
levelMillibel = eq.getBandLevel(idx).toInt(),
|
||||
minLevelMillibel = range[0].toInt(),
|
||||
maxLevelMillibel = range[1].toInt()
|
||||
centerFreqHz = centerFreqsHz[i],
|
||||
levelMillibel = bandLevels[i],
|
||||
minLevelMillibel = minBandLevel,
|
||||
maxLevelMillibel = maxBandLevel
|
||||
)
|
||||
}
|
||||
} else emptyList()
|
||||
|
||||
return AudioEffectsState(
|
||||
equalizerAvailable = eq != null,
|
||||
equalizerEnabled = eq?.enabled ?: false,
|
||||
equalizerAvailable = eqAvailable,
|
||||
equalizerEnabled = eqAvailable && equalizerEnabled,
|
||||
bands = bands,
|
||||
presets = presetNames,
|
||||
currentPreset = if (eq != null) currentPresetIndex else -1,
|
||||
currentPreset = if (eqAvailable) currentPresetIndex else -1,
|
||||
loudnessAvailable = loudnessEnhancer != null,
|
||||
loudnessEnabled = loudnessEnhancer?.enabled ?: false,
|
||||
loudnessGainMillibel = try {
|
||||
loudnessEnhancer?.targetGain ?: 0f
|
||||
} catch (_: Exception) {
|
||||
0f
|
||||
},
|
||||
loudnessEnabled = loudnessEnhancer != null && loudnessEnabled,
|
||||
loudnessGainMillibel = if (loudnessEnhancer != null) loudnessGain.toFloat() else 0f,
|
||||
dynamicsProcessingAvailable = dynamicsProcessing != null,
|
||||
dynamicsProcessingEnabled = dynamicsProcessing?.enabled ?: false
|
||||
dynamicsProcessingEnabled = dynamicsProcessing != null && dynamicsEnabled
|
||||
)
|
||||
}
|
||||
|
||||
fun setEqualizerEnabled(enabled: Boolean) {
|
||||
val eq = equalizer ?: return
|
||||
try {
|
||||
equalizer?.enabled = enabled
|
||||
eq.enabled = enabled
|
||||
equalizerEnabled = enabled
|
||||
prefs.edit { putBoolean(KEY_EQ_ENABLED, enabled) }
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
|
||||
fun setBandLevel(band: Int, levelMillibel: Int) {
|
||||
val eq = equalizer ?: return
|
||||
if (band !in bandLevels.indices) return
|
||||
val level = levelMillibel.coerceIn(minBandLevel, maxBandLevel)
|
||||
if (bandLevels[band] == level && currentPresetIndex == -1) return
|
||||
try {
|
||||
equalizer?.setBandLevel(band.toShort(), levelMillibel.toShort())
|
||||
eq.setBandLevel(band.toShort(), level.toShort())
|
||||
bandLevels[band] = level
|
||||
currentPresetIndex = -1
|
||||
prefs.edit {
|
||||
putInt(KEY_BAND_PREFIX + band, levelMillibel)
|
||||
putInt(KEY_BAND_PREFIX + band, level)
|
||||
putInt(KEY_PRESET, -1)
|
||||
}
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
|
||||
fun setPreset(preset: Int) {
|
||||
val eq = equalizer ?: return
|
||||
try {
|
||||
val eq = equalizer ?: return
|
||||
eq.usePreset(preset.toShort())
|
||||
currentPresetIndex = preset
|
||||
for (b in bandLevels.indices) {
|
||||
bandLevels[b] = eq.getBandLevel(b.toShort()).toInt()
|
||||
}
|
||||
prefs.edit {
|
||||
putInt(KEY_PRESET, preset)
|
||||
for (b in 0 until eq.numberOfBands) {
|
||||
putInt(KEY_BAND_PREFIX + b, eq.getBandLevel(b.toShort()).toInt())
|
||||
}
|
||||
for (b in bandLevels.indices) putInt(KEY_BAND_PREFIX + b, bandLevels[b])
|
||||
}
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
|
||||
fun setLoudnessEnabled(enabled: Boolean) {
|
||||
val le = loudnessEnhancer ?: return
|
||||
try {
|
||||
loudnessEnhancer?.enabled = enabled
|
||||
le.enabled = enabled
|
||||
loudnessEnabled = enabled
|
||||
prefs.edit { putBoolean(KEY_LOUDNESS_ENABLED, enabled) }
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
|
||||
fun setLoudnessGain(gainMillibel: Float) {
|
||||
val le = loudnessEnhancer ?: return
|
||||
val gain = gainMillibel.coerceIn(0f, MAX_LOUDNESS_GAIN.toFloat()).toInt()
|
||||
if (gain == loudnessGain) return
|
||||
try {
|
||||
val gain = gainMillibel.coerceIn(0f, 2000f).toInt()
|
||||
loudnessEnhancer?.setTargetGain(gain)
|
||||
le.setTargetGain(gain)
|
||||
loudnessGain = gain
|
||||
prefs.edit { putInt(KEY_LOUDNESS_GAIN, gain) }
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
|
||||
fun setDynamicsProcessingEnabled(enabled: Boolean) {
|
||||
val dp = dynamicsProcessing ?: return
|
||||
try {
|
||||
dynamicsProcessing?.enabled = enabled
|
||||
dp.enabled = enabled
|
||||
dynamicsEnabled = enabled
|
||||
prefs.edit { putBoolean(KEY_DYNAMICS_ENABLED, enabled) }
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
@@ -237,6 +264,7 @@ class AudioEffectsEngine(context: Context, audioSessionId: Int) {
|
||||
|
||||
private companion object {
|
||||
const val TAG = "AudioEffectsEngine"
|
||||
const val MAX_LOUDNESS_GAIN = 2000
|
||||
const val KEY_EQ_ENABLED = "eq_enabled"
|
||||
const val KEY_PRESET = "eq_preset"
|
||||
const val KEY_BAND_PREFIX = "eq_band_"
|
||||
|
||||
@@ -6,6 +6,10 @@ import android.content.Intent
|
||||
import android.media.AudioManager
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Network
|
||||
import android.net.wifi.WifiManager
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.PowerManager
|
||||
import android.os.SystemClock
|
||||
import android.util.Log
|
||||
import androidx.annotation.OptIn
|
||||
@@ -17,6 +21,7 @@ import androidx.media3.common.PlaybackException
|
||||
import androidx.media3.common.Player
|
||||
import androidx.media3.common.util.UnstableApi
|
||||
import androidx.media3.datasource.DefaultHttpDataSource
|
||||
import androidx.media3.datasource.HttpDataSource
|
||||
import androidx.media3.exoplayer.DefaultLoadControl
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
|
||||
@@ -60,6 +65,15 @@ class FogwavePlaybackService : MediaLibraryService() {
|
||||
|
||||
private var connectivityManager: ConnectivityManager? = null
|
||||
private var networkCallback: ConnectivityManager.NetworkCallback? = null
|
||||
private var defaultNetwork: Network? = null
|
||||
|
||||
// ExoPlayer drops its own wake and Wi-Fi locks once the player is idle after an error, so the
|
||||
// backoff delay would stall while the CPU sleeps. These are held only while a reconnect is pending.
|
||||
private var reconnectWakeLock: PowerManager.WakeLock? = null
|
||||
private var reconnectWifiLock: WifiManager.WifiLock? = null
|
||||
|
||||
private val mainHandler = Handler(Looper.getMainLooper())
|
||||
private var destroyed = false
|
||||
|
||||
private val httpDataSourceFactory: DefaultHttpDataSource.Factory by lazy {
|
||||
DefaultHttpDataSource.Factory()
|
||||
@@ -71,7 +85,9 @@ class FogwavePlaybackService : MediaLibraryService() {
|
||||
}
|
||||
|
||||
private val loadControl = DefaultLoadControl.Builder()
|
||||
.setBufferDurationsMs(5_000, 15_000, 500, 1_000)
|
||||
// Quick start (0.5 s), but after a stall wait for 2.5 s of audio so a weak network does not
|
||||
// turn into a play-stall-play stutter.
|
||||
.setBufferDurationsMs(15_000, 50_000, 500, 2_500)
|
||||
.setPrioritizeTimeOverSizeThresholds(true)
|
||||
.build()
|
||||
|
||||
@@ -166,6 +182,7 @@ class FogwavePlaybackService : MediaLibraryService() {
|
||||
if (retryAttempt != 0) Log.d(TAG, "Reconnect succeeded - resetting backoff")
|
||||
retryAttempt = 0
|
||||
retryJob?.cancel()
|
||||
releaseReconnectLocks()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +196,7 @@ class FogwavePlaybackService : MediaLibraryService() {
|
||||
Log.d(TAG, "Reconnect cancelled - playWhenReady=false (reason=$reason)")
|
||||
}
|
||||
retryJob?.cancel()
|
||||
releaseReconnectLocks()
|
||||
pausedAtMs = SystemClock.elapsedRealtime()
|
||||
return
|
||||
}
|
||||
@@ -203,20 +221,39 @@ class FogwavePlaybackService : MediaLibraryService() {
|
||||
"mediaItem=${lastRequestedItem?.localConfiguration?.uri}",
|
||||
error
|
||||
)
|
||||
scheduleReconnect()
|
||||
scheduleReconnect(maxAttempts = maxRetryAttemptsFor(error))
|
||||
}
|
||||
}
|
||||
|
||||
private fun scheduleReconnect(immediate: Boolean = false) {
|
||||
// A missing stream or an unsupported format will not fix itself, so it gets only a couple of
|
||||
// attempts (a stale token or a short server outage can still recover); network errors get the full backoff.
|
||||
private fun maxRetryAttemptsFor(error: PlaybackException): Int {
|
||||
val httpCode = (error.cause as? HttpDataSource.InvalidResponseCodeException)?.responseCode
|
||||
val permanent = when (error.errorCode) {
|
||||
PlaybackException.ERROR_CODE_IO_BAD_HTTP_STATUS ->
|
||||
httpCode != null && httpCode in 400..499 && httpCode != 408 && httpCode != 429
|
||||
PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND,
|
||||
PlaybackException.ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED,
|
||||
PlaybackException.ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED,
|
||||
PlaybackException.ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED,
|
||||
PlaybackException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED -> true
|
||||
else -> false
|
||||
}
|
||||
return if (permanent) MAX_PERMANENT_ERROR_RETRY_ATTEMPTS else MAX_RETRY_ATTEMPTS
|
||||
}
|
||||
|
||||
private fun scheduleReconnect(immediate: Boolean = false, maxAttempts: Int = MAX_RETRY_ATTEMPTS) {
|
||||
retryJob?.cancel()
|
||||
if (!immediate && retryAttempt >= MAX_RETRY_ATTEMPTS) {
|
||||
if (!immediate && retryAttempt >= maxAttempts) {
|
||||
// Give up instead of keeping the device busy forever; the error stays visible and a tap
|
||||
// on play starts over.
|
||||
Log.w(TAG, "Reconnect abandoned after $retryAttempt attempts")
|
||||
retryAttempt = 0
|
||||
releaseReconnectLocks()
|
||||
player.pause()
|
||||
return
|
||||
}
|
||||
acquireReconnectLocks()
|
||||
val delayMs = if (immediate) 0L else retryDelaysMs.getOrElse(retryAttempt) { retryDelaysMs.last() }
|
||||
retryAttempt++
|
||||
Log.d(TAG, "Reconnect scheduled in ${delayMs}ms (attempt=$retryAttempt)")
|
||||
@@ -224,6 +261,7 @@ class FogwavePlaybackService : MediaLibraryService() {
|
||||
delay(delayMs)
|
||||
if (!player.playWhenReady) {
|
||||
Log.d(TAG, "Reconnect skipped - no longer playWhenReady")
|
||||
releaseReconnectLocks()
|
||||
return@launch
|
||||
}
|
||||
restartStream()
|
||||
@@ -247,6 +285,34 @@ class FogwavePlaybackService : MediaLibraryService() {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION") // WIFI_MODE_FULL_HIGH_PERF is what ExoPlayer itself uses for streaming.
|
||||
private fun acquireReconnectLocks() {
|
||||
try {
|
||||
if (reconnectWakeLock == null) {
|
||||
val pm = getSystemService(Context.POWER_SERVICE) as? PowerManager
|
||||
reconnectWakeLock = pm?.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Fogwave:reconnect")
|
||||
?.apply { setReferenceCounted(false) }
|
||||
}
|
||||
// The timeout is a safety net; the lock is released as soon as the stream is back.
|
||||
reconnectWakeLock?.acquire(RECONNECT_LOCK_TIMEOUT_MS)
|
||||
|
||||
if (reconnectWifiLock == null) {
|
||||
val wm = applicationContext.getSystemService(Context.WIFI_SERVICE) as? WifiManager
|
||||
reconnectWifiLock = wm?.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "Fogwave:reconnect")
|
||||
?.apply { setReferenceCounted(false) }
|
||||
}
|
||||
val wifiLock = reconnectWifiLock
|
||||
if (wifiLock != null && !wifiLock.isHeld) wifiLock.acquire()
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Could not acquire reconnect locks", e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun releaseReconnectLocks() {
|
||||
try { reconnectWakeLock?.takeIf { it.isHeld }?.release() } catch (_: Exception) {}
|
||||
try { reconnectWifiLock?.takeIf { it.isHeld }?.release() } catch (_: Exception) {}
|
||||
}
|
||||
|
||||
private fun registerNetworkCallback() {
|
||||
val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager ?: return
|
||||
connectivityManager = cm
|
||||
@@ -254,8 +320,15 @@ class FogwavePlaybackService : MediaLibraryService() {
|
||||
// Called on a ConnectivityManager thread; ExoPlayer must only be accessed on the main thread.
|
||||
override fun onAvailable(network: Network) {
|
||||
serviceScope.launch {
|
||||
if (retryJob?.isActive == true && player.playWhenReady && player.playbackState != Player.STATE_READY) {
|
||||
Log.d(TAG, "Network available again - reconnecting immediately")
|
||||
val previous = defaultNetwork
|
||||
defaultNetwork = network
|
||||
if (!player.playWhenReady || player.playbackState == Player.STATE_READY) return@launch
|
||||
// After a switch (e.g. Wi-Fi to mobile) a stalled load can sit on a dead socket until
|
||||
// the read timeout, so reopen right away instead of waiting for the error.
|
||||
val switchedWhileStalled = previous != null && previous != network &&
|
||||
player.playbackState == Player.STATE_BUFFERING
|
||||
if (retryJob?.isActive == true || switchedWhileStalled) {
|
||||
Log.d(TAG, "Network available - reconnecting immediately")
|
||||
scheduleReconnect(immediate = true)
|
||||
}
|
||||
}
|
||||
@@ -300,9 +373,7 @@ class FogwavePlaybackService : MediaLibraryService() {
|
||||
}
|
||||
|
||||
Log.d(TAG, "Audio session id for effects: ${player.audioSessionId}")
|
||||
audioEffectsEngine = AudioEffectsEngine(applicationContext, player.audioSessionId).also {
|
||||
AudioEffectsController.attach(it)
|
||||
}
|
||||
createAudioEffectsAsync(player.audioSessionId)
|
||||
|
||||
registerNetworkCallback()
|
||||
|
||||
@@ -319,6 +390,26 @@ class FogwavePlaybackService : MediaLibraryService() {
|
||||
.build()
|
||||
}
|
||||
|
||||
// Creating the effects means several calls into audioserver; done off the main thread so the
|
||||
// service, which starts together with the UI, does not delay the first frames.
|
||||
private fun createAudioEffectsAsync(audioSessionId: Int) {
|
||||
Thread({
|
||||
try {
|
||||
val engine = AudioEffectsEngine(applicationContext, audioSessionId)
|
||||
mainHandler.post {
|
||||
if (destroyed) {
|
||||
engine.release()
|
||||
} else {
|
||||
audioEffectsEngine = engine
|
||||
AudioEffectsController.attach(engine)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Audio effects init failed", e)
|
||||
}
|
||||
}, "FogwaveEffectsInit").start()
|
||||
}
|
||||
|
||||
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaLibrarySession? = mediaLibrarySession
|
||||
|
||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||
@@ -329,7 +420,9 @@ class FogwavePlaybackService : MediaLibraryService() {
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
destroyed = true
|
||||
retryJob?.cancel()
|
||||
releaseReconnectLocks()
|
||||
serviceScope.cancel()
|
||||
networkCallback?.let { cb ->
|
||||
try { connectivityManager?.unregisterNetworkCallback(cb) } catch (_: Exception) {}
|
||||
@@ -349,6 +442,8 @@ class FogwavePlaybackService : MediaLibraryService() {
|
||||
private const val ROOT_ID = "fogwave_root"
|
||||
private const val TAG = "FogwavePlaybackService"
|
||||
private const val MAX_RETRY_ATTEMPTS = 12
|
||||
private const val MAX_PERMANENT_ERROR_RETRY_ATTEMPTS = 2
|
||||
private const val RECONNECT_LOCK_TIMEOUT_MS = 2 * 60_000L
|
||||
private const val LIVE_RESYNC_AFTER_MS = 30_000L
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,17 @@ class RadioPlayerManager(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// Without this a controller whose session went away stays non-null and every command is
|
||||
// silently dropped, leaving the UI stuck on "connecting".
|
||||
private val controllerListener = object : MediaController.Listener {
|
||||
override fun onDisconnected(controller: MediaController) {
|
||||
if (released || controller !== this@RadioPlayerManager.controller) return
|
||||
Log.w(TAG, "MediaController disconnected")
|
||||
dropController()
|
||||
_playerState.value = PlayerState.Idle
|
||||
}
|
||||
}
|
||||
|
||||
// Declared after every property it touches so that nothing is read before initialization.
|
||||
init {
|
||||
connectToPlaybackService()
|
||||
@@ -56,7 +67,9 @@ class RadioPlayerManager(private val context: Context) {
|
||||
private fun connectToPlaybackService() {
|
||||
if (released || controllerFuture != null) return
|
||||
val sessionToken = SessionToken(context, ComponentName(context, FogwavePlaybackService::class.java))
|
||||
val future = MediaController.Builder(context, sessionToken).buildAsync()
|
||||
val future = MediaController.Builder(context, sessionToken)
|
||||
.setListener(controllerListener)
|
||||
.buildAsync()
|
||||
controllerFuture = future
|
||||
future.addListener({
|
||||
if (released) return@addListener
|
||||
@@ -83,6 +96,21 @@ class RadioPlayerManager(private val context: Context) {
|
||||
}, MoreExecutors.directExecutor())
|
||||
}
|
||||
|
||||
/** The controller if it is still connected; a stale one is dropped so the next call reconnects. */
|
||||
private fun connectedController(): MediaController? {
|
||||
val c = controller ?: return null
|
||||
if (c.isConnected) return c
|
||||
dropController()
|
||||
return null
|
||||
}
|
||||
|
||||
private fun dropController() {
|
||||
controller?.removeListener(playerListener)
|
||||
controller = null
|
||||
controllerFuture?.let { MediaController.releaseFuture(it) }
|
||||
controllerFuture = null
|
||||
}
|
||||
|
||||
private fun deriveState(p: Player): PlayerState {
|
||||
p.playerError?.let { return PlayerState.Error(errorMessage(it)) }
|
||||
return when (p.playbackState) {
|
||||
@@ -108,7 +136,7 @@ class RadioPlayerManager(private val context: Context) {
|
||||
fun playStation(station: RadioStation) {
|
||||
Log.d(TAG, "Station requested: ${station.id}")
|
||||
currentStation = station
|
||||
val c = controller
|
||||
val c = connectedController()
|
||||
if (c == null) {
|
||||
pendingStation = station
|
||||
_playerState.value = PlayerState.Connecting
|
||||
@@ -127,7 +155,7 @@ class RadioPlayerManager(private val context: Context) {
|
||||
}
|
||||
|
||||
fun play() {
|
||||
val c = controller
|
||||
val c = connectedController()
|
||||
when {
|
||||
c == null || c.mediaItemCount == 0 -> currentStation?.let { playStation(it) }
|
||||
// A failed, stopped or finished live stream has to be reopened rather than resumed.
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
• Zuverlässige Neuverbindung bei ausgeschaltetem Bildschirm und beim Wechsel zwischen WLAN und Mobilfunk
|
||||
• Weniger Aussetzer bei schwachem Netz
|
||||
• Flüssigere Equalizer-Regler und schnellerer App-Start
|
||||
• Nicht erreichbare Streams werden nicht mehr minutenlang neu versucht
|
||||
|
||||
Neue Versionen gibt es auch auf Gitea: https://git.skysparkle.cc/kalarina/Fogwave/releases
|
||||
@@ -0,0 +1,6 @@
|
||||
• Playback reconnects reliably with the screen off and after switching between Wi-Fi and mobile data
|
||||
• Less stuttering on a weak network
|
||||
• Smoother equalizer sliders and faster app start
|
||||
• Hopeless streams are no longer retried for minutes
|
||||
|
||||
New versions are also available on Gitea: https://git.skysparkle.cc/kalarina/Fogwave/releases
|
||||
@@ -0,0 +1,6 @@
|
||||
• 画面オフ時や Wi-Fi とモバイルデータの切り替え時も確実に再接続
|
||||
• 電波の弱い場所での途切れを軽減
|
||||
• イコライザーのスライダーがなめらかになり、起動も高速化
|
||||
• 再生できないストリームを何分も再試行しなくなりました
|
||||
|
||||
新しいバージョンは Gitea でも入手できます: https://git.skysparkle.cc/kalarina/Fogwave/releases
|
||||
@@ -0,0 +1,6 @@
|
||||
• Patikimas prisijungimas iš naujo išjungus ekraną ir perjungiant Wi-Fi bei mobiliuosius duomenis
|
||||
• Mažiau trūkčiojimų esant silpnam ryšiui
|
||||
• Sklandesni ekvalaizerio slankikliai ir greitesnis paleidimas
|
||||
• Nepasiekiami srautai nebebandomi prijungti kelias minutes
|
||||
|
||||
Naujos versijos taip pat pasiekiamos Gitea: https://git.skysparkle.cc/kalarina/Fogwave/releases
|
||||
@@ -0,0 +1,6 @@
|
||||
• Надёжное переподключение при выключенном экране и при переходе между Wi-Fi и мобильной сетью
|
||||
• Меньше заиканий на слабой сети
|
||||
• Плавные слайдеры эквалайзера и более быстрый запуск
|
||||
• Недоступные потоки больше не переподключаются по несколько минут
|
||||
|
||||
Новые версии также доступны в Gitea: https://git.skysparkle.cc/kalarina/Fogwave/releases
|
||||
@@ -0,0 +1,6 @@
|
||||
• 息屏时以及在 Wi-Fi 与移动数据之间切换后能可靠地重新连接
|
||||
• 网络较弱时卡顿更少
|
||||
• 均衡器滑块更流畅,应用启动更快
|
||||
• 无法播放的音频流不再反复重试数分钟
|
||||
|
||||
新版本也可在 Gitea 获取:https://git.skysparkle.cc/kalarina/Fogwave/releases
|
||||
Reference in New Issue
Block a user