Skip to content

fix: fixing restarting music when pausing it#21

Open
LeonardoFernandesContrera wants to merge 1 commit into
involvex:mainfrom
LeonardoFernandesContrera:main
Open

fix: fixing restarting music when pausing it#21
LeonardoFernandesContrera wants to merge 1 commit into
involvex:mainfrom
LeonardoFernandesContrera:main

Conversation

@LeonardoFernandesContrera

@LeonardoFernandesContrera LeonardoFernandesContrera commented Apr 9, 2026

Copy link
Copy Markdown

Description
Fix the issue where pressing the spacebar while music is playing would restart the track from the beginning instead of pausing and resuming from the current position.

Summary by Sourcery

Bug Fixes:

  • Prevent restarting the track when resuming playback by correctly resuming the existing mpv process or reusing the current track state.

@changeset-bot

changeset-bot Bot commented Apr 9, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 9c406f4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sourcery-ai

sourcery-ai Bot commented Apr 9, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts player resume and play logic so that pausing/resuming via IPC no longer restarts the track, and only starts a new play when there is no active mpv process.

Sequence diagram for PlayerService resume behavior with active ipcSocket

sequenceDiagram
    actor User
    participant PlayerService
    participant IpcSocket

    User->>PlayerService: resume()
    PlayerService->>PlayerService: check ipcSocket and destroyed
    alt ipcSocket exists and not destroyed
        PlayerService->>IpcSocket: sendIpcCommand(set_property, pause, false)
        PlayerService->>PlayerService: isPlaying = true
        alt currentVolume is defined
            PlayerService->>PlayerService: setTimeout(100ms)
            PlayerService->>IpcSocket: sendIpcCommand(set_property, volume, currentVolume)
        end
    end
Loading

Sequence diagram for PlayerService resume behavior when mpvProcess is not running

sequenceDiagram
    actor User
    participant PlayerService
    participant MpvProcess

    User->>PlayerService: resume()
    PlayerService->>PlayerService: check ipcSocket and destroyed
    alt no ipcSocket or destroyed
        PlayerService->>PlayerService: check mpvProcess and currentUrl
        alt mpvProcess is not running and currentUrl is set
            PlayerService->>PlayerService: play(currentUrl, volume = currentVolume)
            PlayerService->>MpvProcess: start playback
        end
    end
Loading

Updated class diagram for PlayerService play and resume logic

classDiagram
    class PlayerService {
        string currentTrackId
        string currentUrl
        number currentVolume
        boolean isPlaying
        any ipcSocket
        any mpvProcess
        play(url, options)
        stop()
        resume()
        sendIpcCommand(args)
    }

    class PlayOptions {
        number volume
        string videoId
    }

    PlayerService ..> PlayOptions : uses

    %% Highlighted behavior changes
    %% - currentTrackId is now set after stop() in play()
    %% - resume() uses ipcSocket pause property when available
    %% - resume() only calls play() when mpvProcess is not running and currentUrl is set
Loading

File-Level Changes

Change Details Files
Ensure play() resets currentTrackId only after stopping existing playback to avoid inconsistent player state.
  • Move currentTrackId assignment in play() to occur after calling stop()
  • Keep currentUrl and volume assignment logic unchanged
source/services/player/player.service.ts
Refine resume() behavior to prefer unpausing the existing mpv instance and only start a new play() when no process is active, preventing track restarts on pause/resume.
  • Guard IPC resume path with a strict truthy check for ipcSocket and its destroyed state
  • Send pause=false to unpause and only then mark isPlaying=true
  • Reapply volume after resume using existing timeout logic
  • Change fallback condition to start play() only when there is no mpvProcess but a currentUrl
  • Add early returns after both IPC-resume and fallback play paths to clarify control flow
source/services/player/player.service.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@kilo-code-bot

kilo-code-bot Bot commented Apr 9, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 1 Warning Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
source/services/player/player.service.ts 532 Redundant double negation - !!this.ipcSocket can be simplified to this.ipcSocket
Files Reviewed (1 file)
  • source/services/player/player.service.ts - 1 warning

Analysis

The PR fixes the issue where pressing spacebar during playback would restart the track instead of pausing/resuming from the current position. The changes are logical and well-structured:

  1. Line 365: Moving currentTrackId assignment after stop() ensures consistent player state
  2. Lines 532-546: The refactored resume() now properly uses IPC socket to unpause existing mpv, and only calls play() when no process is running

Minor Issue: Line 532 uses !!this.ipcSocket which is redundant - a single boolean check is sufficient.

Security: No secrets exposed, no module security issues found.

Breaking Changes: None - this is a bug fix that improves existing behavior.

Fix these issues in Kilo Cloud


Reviewed by minimax-m2.5-20260211 · 214,309 tokens

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the PlayerService by reordering the currentTrackId assignment in the play method to occur after stopping existing playback, and by refining the resume method's logic to correctly set isPlaying and handle different playback scenarios. A review comment highlights a potential race condition in the resume method's use of setTimeout for reapplying volume, suggesting a more robust solution by waiting for mpv confirmation.

Comment on lines 536 to 538
setTimeout(() => {
this.sendIpcCommand(['set_property', 'volume', this.currentVolume]);
}, 100);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using setTimeout with a fixed delay to reapply volume can be fragile. On a slow system or under high load, 100ms might not be enough for the unpause command to be processed by mpv, leading to a race condition where volume is set before the player is ready.

A more robust approach would be to wait for a confirmation from mpv that the player has resumed. This could be done by listening for the property-change event for pause: false before sending the volume command. This would make the resume logic more reliable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant