Skip to content

Commit ce7a89f

Browse files
sozercanclaude
andauthored
fix: use video.paused for play/pause state detection (#87)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0d94049 commit ce7a89f

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

Views/macOS/MiniPlayerWebView.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,16 @@ struct MiniPlayerWebView: NSViewRepresentable {
120120
const titleEl = document.querySelector('.ytmusic-player-bar.title');
121121
const artistEl = document.querySelector('.ytmusic-player-bar.byline');
122122
const progressBar = document.querySelector('#progress-bar');
123-
const playPauseBtn = document.querySelector('.play-pause-button.ytmusic-player-bar');
124123
125124
const title = titleEl ? titleEl.textContent : '';
126125
const artist = artistEl ? artistEl.textContent : '';
127126
const progress = progressBar ? parseInt(progressBar.getAttribute('value') || '0') : 0;
128127
const duration = progressBar ? parseInt(progressBar.getAttribute('aria-valuemax') || '0') : 0;
129128
130-
// Check if playing by looking at the button title
131-
const isPlaying = playPauseBtn ?
132-
playPauseBtn.getAttribute('title') === 'Pause' ||
133-
playPauseBtn.getAttribute('aria-label') === 'Pause' : false;
129+
// Use video element's paused property for language-agnostic detection
130+
// Previously checked button title/aria-label which fails for non-English locales
131+
const video = document.querySelector('video');
132+
const isPlaying = video ? !video.paused : false;
134133
135134
bridge.postMessage({
136135
type: 'STATE_UPDATE',

Views/macOS/SingletonPlayerWebView+ObserverScript.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ extension SingletonPlayerWebView {
211211
lastUpdateTime = now;
212212
213213
try {
214-
const playPauseBtn = document.querySelector('.play-pause-button.ytmusic-player-bar');
215-
const isPlaying = playPauseBtn ?
216-
(playPauseBtn.getAttribute('title') === 'Pause' ||
217-
playPauseBtn.getAttribute('aria-label') === 'Pause') : false;
214+
// Use video element's paused property for language-agnostic detection
215+
// Previously checked button title/aria-label which fails for non-English locales
216+
const video = document.querySelector('video');
217+
const isPlaying = video ? !video.paused : false;
218218
219219
const progressBar = document.querySelector('#progress-bar');
220220

0 commit comments

Comments
 (0)