YT: auto select best matching resolution for used monitor

This commit is contained in:
Rafał Dzięgiel
2021-04-16 09:47:43 +02:00
parent b02f54a3a6
commit 3a998fb91e
4 changed files with 132 additions and 31 deletions

View File

@@ -19,6 +19,7 @@ class ClapperPlayer extends PlayerBase
this.needsFastSeekRestore = false;
this.customVideoTitle = null;
this.windowMapped = false;
this.canAutoFullscreen = false;
this.playOnFullscreen = false;
this.quitOnStop = false;
@@ -54,7 +55,11 @@ class ClapperPlayer extends PlayerBase
if(!this.ytClient)
this.ytClient = new YouTube.YouTubeClient();
this.ytClient.getPlaybackDataAsync(videoId)
const { root } = this.widget;
const surface = root.get_surface();
const monitor = root.display.get_monitor_at_surface(surface);
this.ytClient.getPlaybackDataAsync(videoId, monitor)
.then(data => {
this.customVideoTitle = data.title;
super.set_uri(data.uri);
@@ -121,10 +126,9 @@ class ClapperPlayer extends PlayerBase
this.playlistWidget.addItem(uri);
}
const firstTrack = this.playlistWidget.get_row_at_index(0);
if(!firstTrack) return;
firstTrack.activate();
/* If not mapped yet, first track will play after map */
if(this.windowMapped)
this._playFirstTrack();
}
set_subtitles(source)
@@ -291,6 +295,14 @@ class ClapperPlayer extends PlayerBase
: Gst.filename_to_uri(source);
}
_playFirstTrack()
{
const firstTrack = this.playlistWidget.get_row_at_index(0);
if(!firstTrack) return;
firstTrack.activate();
}
_performCloseCleanup(window)
{
window.disconnect(this.closeRequestSignal);
@@ -522,6 +534,12 @@ class ClapperPlayer extends PlayerBase
}
}
_onWindowMap(window)
{
this.windowMapped = true;
this._playFirstTrack();
}
_onCloseRequest(window)
{
this._performCloseCleanup(window);