Commit 9851cb2c authored by Kourser's avatar Kourser
Browse files

feat(playback): a global speed that survives between launches

A user reported having to set the speed again at each launch. The
podcast settings already speak of "the player's global speed", but it
only lived in the playback controller, which starts at 1×.

The global speed is now saved in PlaybackSettings and restored at launch.
A change made while listening (player, mini bar, lock screen, keyboard)
becomes the global speed, through the controller's new onRateChange. On
a podcast with a speed of its own, the change stays with the episode and
nothing saved moves. Settings › Playback gains a picker, which applies
at once to an episode following the global speed; its label was already
translated.

Live streams now always start at 1×: the saved speed would otherwise
reach them at every launch.

This also fixes a leak: play() was passed nil for a podcast without a
speed, so it kept the speed of the podcast played before. Every episode
now starts at its podcast's speed or at the global one.

Tested on the iPhone Duo simulator: speed kept across a quit, a dedicated
speed leaves the global one alone, the Settings picker applies at once.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 7b4404ee
Loading
Loading
Loading
Loading
+11
Changes for CHANGELOG.md: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,17 @@ adopte le [versionnage sémantique](https://semver.org/lang/fr/).

## [Non publié]

### Ajouté
- **Vitesse de lecture globale** : elle est conservée d'un lancement à l'autre
  et se règle dans Réglages › Lecture. Une vitesse changée pendant l'écoute
  devient la vitesse globale, sauf sur un podcast qui a sa vitesse dédiée (le
  changement vaut alors pour l'épisode en cours) et sur une radio en direct,
  qui démarre toujours à 1×.

### Corrigé
- Après un podcast à vitesse dédiée, les podcasts sans réglage gardaient cette
  vitesse au lieu de revenir à la vitesse globale.

## [1.4.2] - 2026-10-25

iOS uniquement : rien ne change sur Mac.
+4
Changes for Packages/Core/Sources/PlaybackKit/PlaybackController.swift: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -50,6 +50,9 @@ public final class PlaybackController {
    @ObservationIgnored public var onError: (@MainActor (Error) -> Void)?
    /// Called after playback pauses (used to persist the resume position).
    @ObservationIgnored public var onPause: (@MainActor () -> Void)?
    /// Called when the speed is changed during listening (player, lock screen,
    /// keyboard), not when an episode starts at a speed passed to ``play``.
    @ObservationIgnored public var onRateChange: (@MainActor (Float) -> Void)?

    /// Seconds over which the sleep timer fades the volume before pausing.
    static let sleepFadeSeconds: TimeInterval = 20
@@ -216,6 +219,7 @@ public final class PlaybackController {
        playbackRate = rate
        if isPlaying { engine.setRate(rate) }
        notify()
        onRateChange?(rate)
    }

    /// Updates the equalizer for the current playback (live, downloaded files).
+12
Changes for Packages/Core/Tests/PlaybackKitTests/PlaybackControllerTests.swift: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -114,6 +114,18 @@ private func makeEpisode() -> Episode {
        #expect(engine.rate == 1.5)
    }

    @Test func reportsRateChangesButNotARatePassedToPlay() {
        let controller = PlaybackController(engine: FakeAudioEngine())
        var reported: [Float] = []
        controller.onRateChange = { reported.append($0) }

        controller.play(episode: makeEpisode(), rate: 1.25)
        #expect(reported.isEmpty)

        controller.setRate(1.5)
        #expect(reported == [1.5])
    }

    @Test func playAppliesDedicatedRate() {
        let engine = FakeAudioEngine()
        let controller = PlaybackController(engine: engine)
+23 −2
Changes for Skingomz/AppModel.swift: 23 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -34,6 +34,10 @@ final class AppModel {
    @ObservationIgnored let store: LibraryStore
    @ObservationIgnored let fetcher = FeedFetcher()
    @ObservationIgnored private var playback: PlaybackController?
    @ObservationIgnored private var playbackSettings: PlaybackSettings?
    /// The episode playing has no speed of its own and is not a live stream:
    /// changing the speed changes the global one.
    @ObservationIgnored private var followsGlobalRate = true
    @ObservationIgnored private var persistTask: Task<Void, Never>?
    /// One position exchange at a time; one asked for meanwhile runs after it.
    @ObservationIgnored private var exchangingProgress = false
@@ -71,8 +75,14 @@ final class AppModel {
    }

    /// Wires the playback controller (created in the app) for queue advance.
    func configure(playback: PlaybackController) {
    func configure(playback: PlaybackController, settings: PlaybackSettings) {
        self.playback = playback
        playbackSettings = settings
        playback.setRate(settings.playbackRate)
        playback.onRateChange = { [weak self] rate in
            guard let self, followsGlobalRate else { return }
            playbackSettings?.playbackRate = rate
        }
        playback.onFinish = { [weak self] in
            Task { await self?.handlePlaybackFinished() }
        }
@@ -637,6 +647,11 @@ final class AppModel {
        // Skip the intro only on a fresh start, never when resuming mid-episode.
        // Live streams have no position: always start at the live edge.
        let startAt = radio ? 0 : (resume > 0 ? resume : TimeInterval(prefs.skipIntro))
        // A podcast's own speed, otherwise the global one; a live stream plays
        // at normal speed. Only the global speed remembers a change made while
        // listening: the other two keep it for this episode.
        followsGlobalRate = !radio && prefs.playbackRate == nil
        let rate = radio ? 1 : prefs.playbackRate ?? playbackSettings?.playbackRate
        let localURL = downloads.localURL(for: episode)
        // Private feed played from the network: authenticate the stream.
        let streamingAuth = localURL == nil ? credentials(forEpisode: episode) : nil
@@ -645,7 +660,7 @@ final class AppModel {
            episode: episode,
            url: localURL,
            startAt: startAt,
            rate: prefs.playbackRate,
            rate: rate,
            skipEnd: TimeInterval(prefs.skipEnd),
            skipSilence: prefs.skipSilence,
            equalizer: equalizerSettings.activeGains,
@@ -664,6 +679,12 @@ final class AppModel {
        }
    }

    /// Sets the global speed, at once for the episode playing if it follows it.
    func setGlobalRate(_ rate: Float) {
        playbackSettings?.playbackRate = rate
        if followsGlobalRate { playback?.setRate(rate) }
    }

    /// Plays an episode from a position decided elsewhere — another device's,
    /// handed over — rather than from the one saved here.
    func play(_ episode: Episode, at position: TimeInterval) async {
+1 −1
Changes for Skingomz/AppServices.swift: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ final class AppServices: PlaybackActions {
    }

    private func performStart() async {
        model.configure(playback: playback)
        model.configure(playback: playback, settings: playbackSettings)
        playback.setVolume(playbackSettings.engineVolume)
        let model = model
        let playback = playback
Loading