Status and track list suggested by
This commit adds the status, extended track info as well as a tracklist
information as proposed by Jarbasal.
# limitations under the License.
import re
-from enum import Enum
+from enum import Enum, IntEnum
from abc import ABC, abstractmethod
from mycroft.messagebus.message import Message
from .mycroft_skill import MycroftSkill
@@ -29,6 +29,17 @@ class CPSMatchLevel(Enum):
GENERIC = 6
+class CPSTrackStatus(IntEnum):
+ DISAMBIGUATION = 1 # not queued for playback, show in gui
+ PLAYING = 2 # Skill is handling playback internally
+ PLAYING_AUDIOSERVICE = 3 # Skill forwarded playback to audio service
+ QUEUED = 4 # Waiting playback to be handled inside skill
+ QUEUED_AUDIOSERVICE = 5 # Waiting playback in audio service
+ BUFFERING = 6 # Incase it's an online source the buffering state or
+ STALLED = 7 # stalled state helps to know when to show the buffering ui
+ END_OF_MEDIA = 8 # helps to know if we want to do autoplay or something
+
+
class CommonPlaySkill(MycroftSkill, ABC):
""" To integrate with the common play infrastructure of Mycroft
skills should use this base class and override the two methods
@@ -168,6 +179,8 @@ class CommonPlaySkill(MycroftSkill, ABC):
if 'utterance' not in kwargs:
kwargs['utterance'] = self.play_service_string
self.audioservice.play(*args, **kwargs)
+ self.CPS_send_status(uri=args[0],
+ status=CPSTrackStatus.PLAYING_AUDIOSERVICE)
def stop(self):
"""Stop anything playing on the audioservice."""
@@ -224,7 +237,9 @@ class CommonPlaySkill(MycroftSkill, ABC):
pass
def CPS_send_status(self, artist='', track='', album='', image='',
- **kwargs):
+ uri='', track_length=None, elapsed_time=None,
+ playlist_position=None,
+ status=CPSTrackStatus.DISAMBIGUATION, **kwargs):
"""Inform system of playback status.
If a skill is handling playback and wants the playback control to be
@@ -240,13 +255,35 @@ class CommonPlaySkill(MycroftSkill, ABC):
track (str): Track name
album (str): Album title
image (str): url for image to show
+ uri (str): uri for track
+ track_length (float): track length in seconds
+ elapsed_time (float): current offset into track in seconds
+ playlist_postion (int):
"""
data = {'skill': self.name,
+ 'uri': uri,
'artist': artist,
- 'album': artist,
+ 'album': album,
'track': track,
'image': image,
- 'status': None # TODO Add status system
+ 'track_length': track_length,
+ 'elapsed_time': elapsed_time,
+ 'playlist_position': playlist_position,
+ 'status': status
}
data = {**data, **kwargs} # Merge extra arguments
self.bus.emit(Message('play:status', data))
+
+ def CPS_send_tracklist(self, tracklist=None):
+ """Inform system of playlist track info.
+
+ Provides track data for playlist
+
+ Arguments:
+ tracklist (str/list): Tracklist data
+ """
+ tracklist = tracklist or []
+ if not isinstance(tracklist, list):
+ tracklist = [tracklist]
+ for idx, track in enumerate(tracklist):
+ self.CPS_send_status(playlist_position=idx, **track)
