Add: Ability to instant play tv show episode

pull/16/head
Juraj Nyíri 4 years ago
parent 0196ebb031
commit 9a5b62ed9e

@ -18698,7 +18698,7 @@ class Plex {
class PlayController { class PlayController {
constructor(hass, plex, entity) { constructor(hass, plex, entity) {
this.play = async (mediaID) => { this.play = async (mediaID, instantPlay = false) => {
const serverID = await this.plex.getServerID(); const serverID = await this.plex.getServerID();
const command = `am start -a android.intent.action.VIEW 'plex://server://${serverID}/com.plexapp.plugins.library/library/metadata/${mediaID}'`; const command = `am start -a android.intent.action.VIEW 'plex://server://${serverID}/com.plexapp.plugins.library/library/metadata/${mediaID}'`;
console.log(command); console.log(command);
@ -18712,6 +18712,17 @@ class PlayController {
entity_id: this.entity, entity_id: this.entity,
command command
}); });
if (instantPlay) {
console.log('instantPlay');
setTimeout(() => {
console.log('PLAY');
this.hass.callService('androidtv', 'adb_command', {
// eslint-disable-next-line @typescript-eslint/camelcase
entity_id: this.entity,
command: 'CENTER'
});
}, 5000);
}
}; };
this.isPlaySupported = () => { this.isPlaySupported = () => {
return (this.hass.states[this.entity] && return (this.hass.states[this.entity] &&
@ -19694,7 +19705,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
episodePlayButton.addEventListener('click', episodeEvent => { episodePlayButton.addEventListener('click', episodeEvent => {
episodeEvent.stopPropagation(); episodeEvent.stopPropagation();
if (this.plex && this.playController) { if (this.plex && this.playController) {
this.playController.play(episodeData.key.split('/')[3]); this.playController.play(episodeData.key.split('/')[3], true);
} }
}); });
episodeInteractiveArea.append(episodePlayButton); episodeInteractiveArea.append(episodePlayButton);

@ -14,7 +14,7 @@ class PlayController {
this.entity = entity; this.entity = entity;
} }
play = async (mediaID: number): Promise<void> => { play = async (mediaID: number, instantPlay = false): Promise<void> => {
const serverID = await this.plex.getServerID(); const serverID = await this.plex.getServerID();
const command = `am start -a android.intent.action.VIEW 'plex://server://${serverID}/com.plexapp.plugins.library/library/metadata/${mediaID}'`; const command = `am start -a android.intent.action.VIEW 'plex://server://${serverID}/com.plexapp.plugins.library/library/metadata/${mediaID}'`;
@ -29,6 +29,17 @@ class PlayController {
entity_id: this.entity, entity_id: this.entity,
command command
}); });
if (instantPlay) {
console.log('instantPlay');
setTimeout(() => {
console.log('PLAY');
this.hass.callService('androidtv', 'adb_command', {
// eslint-disable-next-line @typescript-eslint/camelcase
entity_id: this.entity,
command: 'CENTER'
});
}, 5000);
}
}; };
isPlaySupported = (): boolean => { isPlaySupported = (): boolean => {

@ -506,7 +506,7 @@ class PlexMeetsHomeAssistant extends HTMLElement {
episodePlayButton.addEventListener('click', episodeEvent => { episodePlayButton.addEventListener('click', episodeEvent => {
episodeEvent.stopPropagation(); episodeEvent.stopPropagation();
if (this.plex && this.playController) { if (this.plex && this.playController) {
this.playController.play(episodeData.key.split('/')[3]); this.playController.play(episodeData.key.split('/')[3], true);
} }
}); });

Loading…
Cancel
Save