From a9dbda455f1086f911af19748d46dfe44b83f78a Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 21 Feb 2020 18:40:46 +0100 Subject: [PATCH] Support for default media player volume --- platypush/plugins/media/__init__.py | 14 ++++++++++---- platypush/plugins/media/chromecast.py | 4 ++++ platypush/plugins/media/kodi.py | 3 +++ platypush/plugins/media/mplayer.py | 4 ++++ platypush/plugins/media/mpv.py | 3 +++ platypush/plugins/media/omxplayer.py | 3 +++ platypush/plugins/media/vlc.py | 2 ++ 7 files changed, 29 insertions(+), 4 deletions(-) diff --git a/platypush/plugins/media/__init__.py b/platypush/plugins/media/__init__.py index 402e1e346..312e613cc 100644 --- a/platypush/plugins/media/__init__.py +++ b/platypush/plugins/media/__init__.py @@ -3,6 +3,8 @@ import functools import os import queue import re +from typing import Optional, List, Dict, Union + import requests import subprocess import tempfile @@ -69,20 +71,23 @@ class MediaPlugin(Plugin): _supported_media_types = ['file', 'torrent', 'youtube'] _default_search_timeout = 60 # 60 seconds - def __init__(self, media_dirs=None, download_dir=None, env=None, + def __init__(self, + media_dirs: Optional[List[str]] = None, + download_dir: Optional[str] = None, + env: Optional[Dict[str, str]] = None, + volume: Optional[Union[float, int]] = None, *args, **kwargs): """ :param media_dirs: Directories that will be scanned for media files when a search is performed (default: none) - :type media_dirs: list :param download_dir: Directory where external resources/torrents will be downloaded (default: ~/Downloads) - :type download_dir: str :param env: Environment variables key-values to pass to the player executable (e.g. DISPLAY, XDG_VTNR, PULSE_SINK etc.) - :type env: dict + + :param volume: Default volume for the player (default: None, maximum volume). """ super().__init__(**kwargs) @@ -134,6 +139,7 @@ class MediaPlugin(Plugin): os.makedirs(self.download_dir, exist_ok=True) self.media_dirs.add(self.download_dir) + self.volume = volume self._videos_queue = [] self._youtube_proc = None diff --git a/platypush/plugins/media/chromecast.py b/platypush/plugins/media/chromecast.py index 20e2e9cab..f079d1fc6 100644 --- a/platypush/plugins/media/chromecast.py +++ b/platypush/plugins/media/chromecast.py @@ -318,6 +318,10 @@ class MediaChromecastPlugin(MediaPlugin): mc.register_status_listener(self.SubtitlesAsyncHandler(mc, subtitle_id)) mc.block_until_active() + + if self.volume: + self.set_volume(volume=self.volume, chromecast=chromecast) + return self.status(chromecast=chromecast) @classmethod diff --git a/platypush/plugins/media/kodi.py b/platypush/plugins/media/kodi.py index f2397b665..84fe825c8 100644 --- a/platypush/plugins/media/kodi.py +++ b/platypush/plugins/media/kodi.py @@ -173,6 +173,9 @@ class MediaKodiPlugin(MediaPlugin): resource = resource[7:] result = self._get_kodi().Player.Open(item={'file': resource}) + if self.volume: + self.set_volume(volume=int(self.volume)) + return self._build_result(result) @action diff --git a/platypush/plugins/media/mplayer.py b/platypush/plugins/media/mplayer.py index 81a38005c..4a4e491c6 100644 --- a/platypush/plugins/media/mplayer.py +++ b/platypush/plugins/media/mplayer.py @@ -268,6 +268,10 @@ class MediaMplayerPlugin(MediaPlugin): self._exec('loadfile', resource, mplayer_args=mplayer_args) self._post_event(MediaPlayEvent, resource=resource) + + if self.volume: + self.set_volume(volume=self.volume) + return self.status() @action diff --git a/platypush/plugins/media/mpv.py b/platypush/plugins/media/mpv.py index 115127955..d3750c271 100644 --- a/platypush/plugins/media/mpv.py +++ b/platypush/plugins/media/mpv.py @@ -140,6 +140,9 @@ class MediaMpvPlugin(MediaPlugin): resource = resource[7:] self._player.play(resource) + if self.volume: + self.set_volume(volume=self.volume) + return self.status() @action diff --git a/platypush/plugins/media/omxplayer.py b/platypush/plugins/media/omxplayer.py index d44ac22f1..ed62e53a5 100644 --- a/platypush/plugins/media/omxplayer.py +++ b/platypush/plugins/media/omxplayer.py @@ -82,6 +82,9 @@ class MediaOmxplayerPlugin(MediaPlugin): self.logger.exception(e) self._player.pause() + if self.volume: + self.set_volume(volume=self.volume) + self._player.play() return self.status() diff --git a/platypush/plugins/media/vlc.py b/platypush/plugins/media/vlc.py index cb04be287..eb06fbec2 100644 --- a/platypush/plugins/media/vlc.py +++ b/platypush/plugins/media/vlc.py @@ -167,6 +167,8 @@ class MediaVlcPlugin(MediaPlugin): self._player.video_set_subtitle_file(subtitles) self._player.play() + if self.volume: + self.set_volume(volume=self.volume) if fullscreen or self._default_fullscreen: self.set_fullscreen(True)