forked from Wobbl/Wobuzz
Implemented basic MPRIS integration.
This commit is contained in:
parent
e845c41ca3
commit
9416ac6737
6 changed files with 160 additions and 40 deletions
|
@ -4,8 +4,10 @@ import time
|
|||
import threading
|
||||
import pygame.mixer
|
||||
import pygame.event
|
||||
|
||||
from .playlist import Playlist
|
||||
from .track_progress_timer import TrackProgress
|
||||
from .mpris import MPRISServer
|
||||
|
||||
|
||||
class Player:
|
||||
|
@ -21,6 +23,10 @@ class Player:
|
|||
self.history = Playlist(self.app, "History")
|
||||
self.current_playlist = None
|
||||
|
||||
self.mpris_server = MPRISServer(self.app)
|
||||
# start mpris server in a thread (daemon = exit with main thread)
|
||||
threading.Thread(target=self.mpris_server.start, daemon=True).start()
|
||||
|
||||
self.playing = False
|
||||
self.paused = False
|
||||
|
||||
|
@ -34,6 +40,7 @@ class Player:
|
|||
self.paused = False
|
||||
|
||||
self.app.gui.on_playstate_update()
|
||||
self.mpris_server.exec_async(self.mpris_server.set_metadata(self.current_playlist.current_track.metadata))
|
||||
|
||||
# cache next track so it immediately starts when the current track finishes
|
||||
self.cache_next_track()
|
||||
|
@ -191,3 +198,22 @@ class Player:
|
|||
self.current_playlist = playlist
|
||||
|
||||
self.start_playing()
|
||||
|
||||
def toggle_playing(self):
|
||||
if self.playing and self.paused: # paused
|
||||
self.unpause()
|
||||
|
||||
elif self.playing: # playing
|
||||
self.pause()
|
||||
|
||||
# stopped but tracks in the current playlist
|
||||
elif self.current_playlist is not None and self.current_playlist.has_tracks():
|
||||
self.start_playing()
|
||||
|
||||
elif self.current_playlist is None:
|
||||
if self.app.settings.latest_playlist is not None:
|
||||
for playlist in self.app.library.playlists: # get loaded playlist by the path of the latest playlist
|
||||
if playlist.path == self.app.settings.latest_playlist:
|
||||
self.start_playlist(playlist)
|
||||
|
||||
break
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue