This approach seems to work: rather than poll the current time manually to stop playback, use the pyglet clock scheduler to run a stop callback once after a given interval. This is precise enough for my use case ;-)
player = None
def stop_callback(dt):
if player != None:
player.stop()
def play_sound_interval(mp3File, start=None, end=None):
sound = pyglet.resource.media(mp3File)
global player
player = pyglet.media.ManagedSoundPlayer()
player.queue(sound)
if start != None:
player.seek(start)
if end != None and start != None:
pyglet.clock.schedule_once(stop_callback, end-start)
elif end != None and start == None:
pyglet.clock.schedule_once(stop_callback, end)
player.play()