8000 fix: use video.paused for play/pause state detection by sozercan · Pull Request #87 · sozercan/kaset · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@sozercan
Copy link
Owner

Summary

  • Fix play/pause icon not updating when music is playing
  • Replace localized button attribute check (title === 'Pause') with video element's paused property
  • This change is language-agnostic and works regardless of YouTube Music's display language

Root Cause

The JavaScript observer scripts checked for hardcoded English text in the play/pause button's title and aria-label attributes. When YouTube Music is displayed in a non-English language (e.g., German, Spanish), these attributes contain localized text, causing isPlaying to always return false.

Fix

Use video.paused property directly instead of checking button text:

// Before (fails for non-English locales)
const playPauseBtn = document.querySelector('.play-pause-button.ytmusic-player-bar');
const isPlaying = playPauseBtn?.getAttribute('title') === 'Pause';

// After (language-agnostic)
const video = document.querySelector('video');
const isPlaying = video ? !video.paused : false;

Test plan

  • Verify play/pause icon updates correctly when music starts/stops
  • Test with YouTube Music set to a non-English language
  • Verify keyboard shortcuts (Space) still toggle play/pause correctly
  • Verify media keys still work correctly

Fixes #16

🤖 Generated with Claude Code

The play/pause icon was not updating because the JavaScript observer
checked for hardcoded English button text ("Pause") in the title and
aria-label attributes. This fails when YouTube Music is displayed in
a non-English language.

Replace the localized button attribute check with the video element's
`paused` property, which is language-agnostic and more reliable.

Fixes #16

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings January 26, 2026 07:22
Copy link
Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes playback state detection language-agnostic by relying on the <video> element’s paused property instead of localized button text, fixing incorrect play/pause icon state in non-English YouTube Music locales.

Changes:

  • In SingletonPlayerWebView’s observer script, replace checks against the play/pause button’s title/aria-label attributes with video.paused to derive isPlaying.
  • In MiniPlayerWebView’s observer script, remove the now-unneeded playPauseBtn lookup and similarly compute isPlaying from the video element’s paused property.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Views/macOS/SingletonPlayerWebView+ObserverScript.swift Updates the main player state observer to compute isPlaying from document.querySelector('video') and its paused property, making play/pause detection locale-independent.
Views/macOS/MiniPlayerWebView.swift Aligns the mini player’s observer script with the same video.paused-based isPlaying logic and removes the unused play/pause button reference.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sozercan sozercan merged commit ce7a89f into main Jan 26, 2026
12 checks passed
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.

Paused icon does not change to playing icon

2 participants

0