Standardized omxplayer returned attributes and volume management

This commit is contained in:
Fabio Manganiello 2019-07-12 20:12:59 +02:00
parent 50313580fd
commit 654c61ec51

View file

@ -111,14 +111,14 @@ class MediaOmxplayerPlugin(MediaPlugin):
def voldown(self): def voldown(self):
""" Volume down by 10% """ """ Volume down by 10% """
if self._player: if self._player:
self._player.set_volume(max(-6000, self._player.volume()-1000)) self._player.set_volume(max(0, self._player.volume()-0.1))
return self.status() return self.status()
@action @action
def volup(self): def volup(self):
""" Volume up by 10% """ """ Volume up by 10% """
if self._player: if self._player:
self._player.set_volume(min(0, self._player.volume()+1000)) self._player.set_volume(min(1, self._player.volume()+0.1))
return self.status() return self.status()
@action @action
@ -229,7 +229,7 @@ class MediaOmxplayerPlugin(MediaPlugin):
""" """
if self._player: if self._player:
self._player.set_seek(position) self._player.seek(position)
return self.status() return self.status()
@action @action
@ -241,10 +241,8 @@ class MediaOmxplayerPlugin(MediaPlugin):
:type volume: int :type volume: int
""" """
# Transform a [0,100] value to an OMXPlayer volume in [-6000,0]
volume = 60.0*volume - 6000
if self._player: if self._player:
self._player.set_volume(volume) self._player.set_volume(volume/100)
return self.status() return self.status()
@action @action
@ -254,16 +252,22 @@ class MediaOmxplayerPlugin(MediaPlugin):
:returns: A dictionary containing the current state. :returns: A dictionary containing the current state.
Example:: Format::
output = { output = {
"source": "https://www.youtube.com/watch?v=7L9KkZoNZkA", "duration": Duration in seconds,
"state": "play", "filename": Media filename,
"volume": 80, "fullscreen": true or false,
"elapsed": 123, "mute": true or false,
"duration": 300, "path": Media path
"width": 800, "pause": true or false,
"height": 600 "position": Position in seconds
"seekable": true or false
"state": play, pause or stop
"title": Media title
"url": Media url
"volume": Volume between 0 and 100
"volume_max": 100,
} }
""" """
@ -283,12 +287,12 @@ class MediaOmxplayerPlugin(MediaPlugin):
'mute': self._player._is_muted, 'mute': self._player._is_muted,
'path': self._player.get_source(), 'path': self._player.get_source(),
'pause': state == PlayerState.PAUSE.value, 'pause': state == PlayerState.PAUSE.value,
'position': self._player.position(), 'position': max(0, self._player.position()),
'seekable': self._player.can_seek(), 'seekable': self._player.can_seek(),
'state': state, 'state': state,
'title': urllib.parse.unquote(self._player.get_source()).split('/')[-1] if self._player.get_source().startswith('file://') else None, 'title': urllib.parse.unquote(self._player.get_source()).split('/')[-1] if self._player.get_source().startswith('file://') else None,
'url': self._player.get_source(), 'url': self._player.get_source(),
'volume': self._player.volume(), 'volume': self._player.volume() * 100,
'volume_max': 100, 'volume_max': 100,
} }
else: else: