50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import sqlite3
|
|
import os
|
|
import playTrack, playControl
|
|
|
|
|
|
DB_PATH = '/home/pi/SandTable/db.sqlite3'
|
|
|
|
|
|
def PlayQ():
|
|
connection = sqlite3.connect(DB_PATH)
|
|
cursor = connection.cursor()
|
|
|
|
playControl.init_control_table()
|
|
playControl.set_command(playControl.COMMAND_PLAY)
|
|
playControl.set_status(playControl.STATUS_PLAYING, pid=os.getpid())
|
|
|
|
# Reading the queue table
|
|
rows = cursor.execute("SELECT id, file, track_length, pic FROM sandtable_queue").fetchall()
|
|
|
|
# Let the first playTrack() call ask the device for its position; after
|
|
# that we just keep tracking it in memory as moves complete.
|
|
coords = None
|
|
|
|
# While there are entries in the table
|
|
while rows:
|
|
file = rows[0][1]
|
|
|
|
# Playing the track in the first index
|
|
coords = playTrack.playTrack(file, coords=coords)
|
|
|
|
# A stop request means playTrack() bailed out mid-file - leave this
|
|
# track in the queue (so it picks back up / can be replayed) rather
|
|
# than deleting it like a normally-finished or skipped ("next")
|
|
# track.
|
|
if playControl.get_command() == playControl.COMMAND_STOP:
|
|
break
|
|
|
|
# Deleting the first track that was just played
|
|
cursor.execute("DELETE FROM sandtable_queue WHERE id = ?", (rows[0][0],))
|
|
connection.commit()
|
|
|
|
# Reading the new table
|
|
rows = cursor.execute("SELECT id, file, track_length, pic FROM sandtable_queue").fetchall()
|
|
|
|
playControl.set_status(playControl.STATUS_IDLE, pid=0)
|
|
connection.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
PlayQ() |