diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ce9a10a..209b306 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,6 +7,10 @@ You need to have: - Python 2.7 (for now, sorry 😢) and `pip` installed - The `pipenv` tool ([See here for installation instructions](https://pipenv.readthedocs.io/en/latest/install/#installing-pipenv)) +You should consider installing: + +- Python 3.6 or above (ideally 3.7 or above) + ## Setting up your environment - Clone this repo diff --git a/README.md b/README.md index 644316c..e27a49d 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,25 @@ back short audio tracks. Written by Mark Mollineaux (2013) +## Installation and running + +### Prerequisites + +You need the following: + +- Python 2.7 and `pip` +- Recommended: AVBin for playing spotbox files (https://avbin.github.io/AVbin/Download.html) + +Use `pip install` to install: + +- `pip install pyglet` + +### Steps to install + +- Download the spotbox code from GitHub (clone or zip) +- Navigate to the repository +- Create a shortcut, script, or alias to run `python spotbox.py`. + ## Contributing Read the [contribution guidelines](./CONTRIBUTING.md) to help out. diff --git a/spotbox/spotbox.py b/spotbox/spotbox.py index ef3d5bd..1094e42 100644 --- a/spotbox/spotbox.py +++ b/spotbox/spotbox.py @@ -39,6 +39,6 @@ playback = sbplayback.iTunesPlayback() else: # this class does nothing for load/play/stop/etc, just pass for each - playback = sbplayback.Playback() + playback = sbplayback.PygletPlayback() spotboxgui = SpotboxTkInterface(configuration, datasheets, playback) spotboxgui.run_continuously() diff --git a/spotbox/spotboxgui.py b/spotbox/spotboxgui.py index 73fe2a5..63d2a2c 100644 --- a/spotbox/spotboxgui.py +++ b/spotbox/spotboxgui.py @@ -158,6 +158,8 @@ def _loadspot(self, spottext, spotnumber): self._menus.filetimetoload) def _playspot(self, spotnumber): + self._stop() + self._playback.play(spotnumber) countdowntostart = self.countdownarray[spotnumber] for countdown in self.countdownarray: diff --git a/spotbox/spotboxplayback.py b/spotbox/spotboxplayback.py index fb7a9f2..3ae10bb 100644 --- a/spotbox/spotboxplayback.py +++ b/spotbox/spotboxplayback.py @@ -2,8 +2,9 @@ """SPOTBOX media playback backend""" -# Note-- non-iTunes mode is not yet fully implemented. +import os +from spotboxconfig import folder_configuration class Playback: """A playback object, allows for audio files to be loaded, played back, @@ -74,28 +75,53 @@ def play(self, spotnumber): class PygletPlayback(Playback): + """Provide playback support using the Pyglet library. + + See https://bitbucket.org/pyglet/pyglet/overview""" def __init__(self): - import pyglet - self.playerarray = [] + self.players = {} + self.media = {} def initialize_one_player(self, spotnumber): - pygplayer = self.pyglet.media.Player() - self.playerarray.append(pygplayer) + import pyglet + pygplayer = pyglet.media.Player() + + if spotnumber in self.players: + # Make sure to free up queues and player resources + self.players[spotnumber].delete() + + self.players[spotnumber] = pygplayer def stop(self): - for player in self.playerarray: + for spot_number, player in self.players.iteritems(): player.pause() + # Need to check to avoid OpenGL access exception (ugh) + if player.time > 0: + player.seek(0.0) + def load(self, spotnumber, filepath): - # at moment, throws "NOT A WAVE" exception, even for .wav - print filepath - media = self.pyglet.media.load(filepath, streaming=False) - del self.playerarray[spotnumber] - self.playerarray[spotnumber].queue(media) + import pyglet + + # To support non-WAV files, you may need to install AVBin (http://avbin.github.io/AVbin) + self.media[spotnumber] = pyglet.media.load(os.path.join(folder_configuration['MEDIADIRECTORY'], filepath)) + + return True def play(self, spotnumber): - self.playerarray[spotnumber].play() + player = self.players[spotnumber] + + if player.source is None: + # re-enqueue media + player.queue(self.media[spotnumber]) + + if player.time > 0: + # play from beginning + player.seek(0) + + player.play() + if __name__ == '__main__': pass