Play next works
This commit is contained in:
parent
8abf4caf4a
commit
aeda0880dd
14
app/model.py
14
app/model.py
@ -13,6 +13,9 @@ from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from config import Config
|
||||
|
||||
from log import ERROR, DEBUG
|
||||
# from log import INFO, ERROR, DEBUG
|
||||
|
||||
# "Constants"
|
||||
# Instantiate logging
|
||||
pytiger.logging.config.basic_config(stderr=False, level=logging.INFO)
|
||||
@ -88,6 +91,7 @@ class Tracks(Base):
|
||||
|
||||
@classmethod
|
||||
def get_or_create(cls, path):
|
||||
DEBUG(f"get_or_create(cls, {path})")
|
||||
try:
|
||||
track = session.query(cls).filter(cls.path == path).one()
|
||||
except NoResultFound:
|
||||
@ -105,6 +109,16 @@ class Tracks(Base):
|
||||
print(f"Can't find track id {id}")
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def get_track(id):
|
||||
try:
|
||||
DEBUG(f"get_track({id})")
|
||||
track = session.query(Tracks).filter(Tracks.id == id).one()
|
||||
return track
|
||||
except NoResultFound:
|
||||
ERROR(f"get_track({id}): not found")
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def search_titles(text):
|
||||
return (
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import vlc
|
||||
import sys
|
||||
|
||||
from log import DEBUG
|
||||
# from log import INFO, ERROR, DEBUG
|
||||
from log import DEBUG, ERROR
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import QApplication, QDialog, QMainWindow
|
||||
@ -44,11 +44,88 @@ class RepeatedTimer:
|
||||
self.is_running = False
|
||||
|
||||
|
||||
class Music:
|
||||
def __init__(self):
|
||||
self.current_track = {
|
||||
"player": None,
|
||||
"meta": None
|
||||
}
|
||||
|
||||
self.next_track = {
|
||||
"player": None,
|
||||
"meta": None
|
||||
}
|
||||
|
||||
self.previous_track = {
|
||||
"player": None,
|
||||
"meta": None
|
||||
}
|
||||
|
||||
def get_current_artist(self):
|
||||
return self.current_track['meta'].artist
|
||||
|
||||
def get_current_duration(self):
|
||||
return self.current_track['meta'].duration
|
||||
|
||||
def get_current_fade_at(self):
|
||||
return self.current_track['meta'].fade_at
|
||||
|
||||
def get_current_playtime(self):
|
||||
return self.current_track['player'].get_time()
|
||||
|
||||
def get_current_silence_at(self):
|
||||
return self.current_track['meta'].silence_at
|
||||
|
||||
def get_current_title(self):
|
||||
return self.current_track['meta'].title
|
||||
|
||||
def get_last_artist(self):
|
||||
return self.last_track['meta'].artist
|
||||
|
||||
def get_last_title(self):
|
||||
return self.last_track['meta'].title
|
||||
|
||||
def get_next_artist(self):
|
||||
return self.next_track['meta'].artist
|
||||
|
||||
def get_next_title(self):
|
||||
return self.next_track['meta'].title
|
||||
|
||||
def play_next(self):
|
||||
if self.previous_track['player']:
|
||||
self.previous_track['player'].release()
|
||||
if self.current_track['player']:
|
||||
self.current_track['player'].stop()
|
||||
self.previous_track = self.current_track
|
||||
self.current_track = self.next_track
|
||||
self.next_track = {
|
||||
"player": None,
|
||||
"meta": None
|
||||
}
|
||||
|
||||
self.current_track['player'].play()
|
||||
|
||||
def resume_last(self):
|
||||
pass
|
||||
|
||||
def set_next_track(self, id):
|
||||
track = Tracks.get_track(id)
|
||||
if not track:
|
||||
ERROR(f"set_next_track({id}): can't find track")
|
||||
return None
|
||||
|
||||
self.next_track['player'] = vlc.MediaPlayer(
|
||||
os.path.join(Config.ROOT, track.path))
|
||||
self.next_track['meta'] = track
|
||||
return track.id
|
||||
|
||||
|
||||
class Window(QMainWindow, Ui_MainWindow):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setupUi(self)
|
||||
self.connectSignalsSlots()
|
||||
self.music = Music()
|
||||
|
||||
record = Settings.get_int("mainwindow_x")
|
||||
x = record.f_int or 1
|
||||
@ -92,12 +169,17 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
def connectSignalsSlots(self):
|
||||
self.fileButton.clicked.connect(self.selectFile)
|
||||
self.databaseButton.clicked.connect(self.selectFromDatabase)
|
||||
self.actionPlay_selected.triggered.connect(self.play_selected)
|
||||
self.actionPlay_selected.triggered.connect(self.play_next)
|
||||
self.actionPlay_next.triggered.connect(self.play_next)
|
||||
self.playlist.itemSelectionChanged.connect(self.set_next)
|
||||
|
||||
def selectFromDatabase(self):
|
||||
dlg = DbDialog(self)
|
||||
dlg.exec()
|
||||
|
||||
def play_next(self):
|
||||
self.music.play_next()
|
||||
|
||||
def play_selected(self):
|
||||
if self.playlist.selectionModel().hasSelection():
|
||||
row = self.playlist.currentRow()
|
||||
@ -124,6 +206,14 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# track = Track(fname)
|
||||
# self.add_to_playlist(track)
|
||||
|
||||
def set_next(self):
|
||||
if self.playlist.selectionModel().hasSelection():
|
||||
row = self.playlist.currentRow()
|
||||
track_id = int(self.playlist.item(row, 0).text())
|
||||
DEBUG(f"set_next: track_id={track_id}")
|
||||
if self.music.set_next_track(track_id) != track_id:
|
||||
ERROR("Can't set next track")
|
||||
|
||||
def add_to_playlist(self, track):
|
||||
"""
|
||||
Add track to playlist
|
||||
|
||||
@ -322,6 +322,7 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
<string>Pla&ylist</string>
|
||||
</property>
|
||||
<addaction name="actionPlay_selected"/>
|
||||
<addaction name="actionPlay_next"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menuPlaylist"/>
|
||||
@ -333,12 +334,17 @@ border: 1px solid rgb(85, 87, 83);</string>
|
||||
</widget>
|
||||
<action name="actionPlay_selected">
|
||||
<property name="text">
|
||||
<string>Play selected</string>
|
||||
<string>&Play selected</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Return</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPlay_next">
|
||||
<property name="text">
|
||||
<string>Play &next</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user