From 4c7b00cb1dd3c1432635ff51b616da3f142bdb8a Mon Sep 17 00:00:00 2001 From: William Date: Sun, 5 Nov 2023 15:51:06 +0100 Subject: [PATCH 1/2] fix:play correct media --- custom_components/mopidy/speaker.py | 40 +++++++++++++---------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/custom_components/mopidy/speaker.py b/custom_components/mopidy/speaker.py index 70c66d2..7e04923 100644 --- a/custom_components/mopidy/speaker.py +++ b/custom_components/mopidy/speaker.py @@ -337,17 +337,6 @@ def uri(self): """Return the URI of the current track""" return self._attr_track_uri -# class MopidyQueue: -# """Mopidy doesn't provide information about the playlist a song which is being played""" -# api: MopidyAPI | None = None - -# _queue: list | None = None - -# def __init__(self): -# self._queue = [] - - - class MopidySpeaker: hass: HomeAssistant | None = None @@ -450,10 +439,6 @@ def update(self): _LOGGER.debug(str(error)) return - # if not self._attr_is_available: - # _LOGGER.debug("Waiting for network connectivity to be established") - # return - self._attr_software_version = self.api.rpc_call("core.get_version") self._attr_supported_uri_schemes = self.api.rpc_call("core.get_uri_schemes") self._attr_consume_mode = self.api.tracklist.get_consume() @@ -519,9 +504,17 @@ def media_pause(self): def media_play(self, index=None): """Play the current media""" - if isinstance(index, int): - self.api.playback.play(tlid=index) - else: + _LOGGER.debug("index: %s", index) + try: + int(index) + current_tracks = self.api.tracklist.get_tl_tracks() + self.api.playback.play( + tlid=current_tracks[index].tlid + ) + + except Exception as error: + _LOGGER.error("The specified index %s could not be resolved", index) + _LOGGER.debug(str(error)) self.api.playback.play() def media_previous_track(self): @@ -552,23 +545,24 @@ def play_media(self, media_type, media_id, **kwargs): media_uris = [ x.uri for x in self.library.browse(media_id)] if enqueue == MediaPlayerEnqueue.ADD: + # Add media uris to end of the queue self.queue_tracks(media_uris) self.media_play() elif enqueue == MediaPlayerEnqueue.NEXT: + # Add media uris to queue after current playing track index = self.queue_position self.queue_tracks(media_uris, at_position=index+1) elif enqueue == MediaPlayerEnqueue.PLAY: - # tracks = self.tracklist_uris + # Insert media uris before current playing track into queue and play first of new uris index = self.queue_position - # new_media_uris = tracks[:index] + media_uris + tracks[index+1:] - self.clear_queue() - # self.queue_tracks(new_media_uris) self.queue_tracks(media_uris, at_position=index) self.media_play(index) elif enqueue == MediaPlayerEnqueue.REPLACE: + # clear queue and replace with media uris + self.media_stop() self.clear_queue() self.queue_tracks(media_uris) self.media_play() @@ -581,6 +575,8 @@ def queue_tracks(self, uris, at_position=None): """Queue tracks""" if len(uris) > 0: self.api.tracklist.add(uris=uris, at_position=at_position) + self._attr_tracklist = self.api.tracklist.get_tracks() + self._attr_queue_position = self.api.tracklist.index() def restore_snapshot(self): """Restore a snapshot""" From 5d80144135e3b82bdf30bc427e2bb24cdb339439 Mon Sep 17 00:00:00 2001 From: William Date: Sun, 5 Nov 2023 15:54:27 +0100 Subject: [PATCH 2/2] chore:version bump --- custom_components/mopidy/manifest.json | 2 +- mopidy-CHANGELOG.md | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/custom_components/mopidy/manifest.json b/custom_components/mopidy/manifest.json index 8b03d0e..98fa2fc 100644 --- a/custom_components/mopidy/manifest.json +++ b/custom_components/mopidy/manifest.json @@ -10,7 +10,7 @@ "requirements": [ "mopidyapi>=1.0.0" ], - "version": "2.0.2", + "version": "2.0.3", "zeroconf": [ { "type": "_mopidy-http._tcp.local." diff --git a/mopidy-CHANGELOG.md b/mopidy-CHANGELOG.md index c5b7996..317efda 100644 --- a/mopidy-CHANGELOG.md +++ b/mopidy-CHANGELOG.md @@ -4,9 +4,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.0.3] - 2023-11-05 + +### Fixed + +- fix `media_player.play_media` service `enqueue.play` behaviour + ## [2.0.2] - 2023-11-02 -### Fixed wrong varname for youtube (#40) +### Fixed + +- wrong varname for youtube (#40) ## [2.0.1] - 2023-10-31