Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,25 @@ back short audio tracks.

Written by Mark Mollineaux (2013) <bufordsharkley@gmail.com>

## 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.
Expand Down
2 changes: 1 addition & 1 deletion spotbox/spotbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 2 additions & 0 deletions spotbox/spotboxgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ def _loadspot(self, spottext, spotnumber):
self._menus.filetimetoload)

def _playspot(self, spotnumber):
self._stop()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since iTunes only has one playback queue, playing a new spot will stop playing that spot and start playing the new spot.

With the Pyglet player, it's possible to play multiple spots simultaneously, which is probably not what most people expect. Adding an explicit call to stop doesn't affect iTunes playback but explicitly implements behavior that was a side effect of iTunes mode.


self._playback.play(spotnumber)
countdowntostart = self.countdownarray[spotnumber]
for countdown in self.countdownarray:
Expand Down
50 changes: 38 additions & 12 deletions spotbox/spotboxplayback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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