Skip to content

Commit

Permalink
fix media track turning off
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Apr 6, 2024
1 parent 0b915c1 commit e71db35
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ControllerApp implements Initializable {
private static final String GET_MEDIA_NAME_SCRIPT = "document.getElementsByClassName('style-scope ytd-watch-metadata')[0].firstElementChild.textContent;";
private static final String GET_SONG_NAME_SCRIPT = "externalAPI.getCurrentTrack().title;";
private static final String MEDIA_INJECT_SCRIPT = "document.querySelector('video').addEventListener('ended', e => {window.media.playNext(true)});";
private static final String AUTO_MEDIA_INJECT_SCRIPT = "setTimeout(() => {if (document.querySelector('.ytp-time-current').textContent == \"0:00\") {document.querySelector('.ytp-cued-thumbnail-overlay').click();}}, 1500)";

// UI elements
@FXML
Expand Down Expand Up @@ -77,7 +78,7 @@ private void setupPlayer() {

playerWebEngine.getLoadWorker().stateProperty().addListener((observable, oldValue, newValue) -> {
if (newValue == Worker.State.SUCCEEDED) {
playerWebEngine.executeScript(SONG_INJECT_SCRIPT);
playerWebEngine.executeScript(AUTO_SONG_INJECT_SCRIPT);
CookieUtils.saveCookies();
}
});
Expand Down Expand Up @@ -125,6 +126,7 @@ private void injectScript(WebEngine webEngine) {
}

webEngine.executeScript(MEDIA_INJECT_SCRIPT);
webEngine.executeScript(AUTO_MEDIA_INJECT_SCRIPT);
}

// Inner class to bridge between Java and JavaScript
Expand Down

0 comments on commit e71db35

Please sign in to comment.