Support for default media player volume
This commit is contained in:
parent
70fe2459de
commit
a9dbda455f
7 changed files with 29 additions and 4 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue