Created
January 5, 2009 20:49
-
-
Save pbuyle/43536 to your computer and use it in GitHub Desktop.
Play an audio file on a TuxDroid with GStreamer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
from tuxisalive.api.TuxAPI import * | |
import pygst | |
pygst.require("0.10") | |
import gst | |
import gtk | |
__author__="pbuyle" | |
__date__ ="$05-janv.-2009 21:21:57$" | |
#The URI of the file to play (can be a remote HTTP URL) | |
FILE_URI = "http://www.sirgalahad.org/paul/doom/mp3/d1end.mp3" | |
tux = TuxAPI('127.0.0.1', 270) | |
tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'TuxGTK', 'NONE') | |
tux.server.waitConnected(10.0) | |
tux.dongle.waitConnected(10.0) | |
tux.radio.waitConnected(10.0) | |
if tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL): | |
player = gst.element_factory_make('playbin', 'player') | |
player.set_property('video-sink', gst.element_factory_make('fakesink', 'fakesink')) | |
out = gst.element_factory_make('alsasink', 'out') | |
out.set_property('device', 'plughw:TuxDroid') | |
player.set_property('audio-sink', out) | |
player.set_property('uri', FILE_URI) | |
bus = player.get_bus() | |
bus.add_signal_watch() | |
def on_volume(key, delay): | |
volume = player.get_property('volume') | |
if key == K_VOLUMEPLUS and volume < 10.0: | |
volume += 0.1 | |
elif key == K_VOLUMEMINUS and volume > 0: | |
volume -= 0.1 | |
player.set_property('volume', volume) | |
print 'set volume to %f' % volume | |
tux.button.remote.registerEventOnPressed(on_volume, K_VOLUMEPLUS) | |
tux.button.remote.registerEventOnPressed(on_volume, K_VOLUMEMINUS) | |
def on_bus_message(bus, message): | |
t = message.type | |
if t == gst.MESSAGE_EOS: | |
player.set_state(gst.STATE_NULL) | |
elif t == gst.MESSAGE_ERROR: | |
player.set_state(gst.STATE_NULL) | |
err, debug = message.parse_error() | |
print "Error: %s" % err, debug | |
def on_standby(*args): | |
player.set_state(gst.STATE_NULL) | |
gtk.main_quit() | |
bus.connect("message", on_bus_message) | |
player.set_state(gst.STATE_PLAYING) | |
tux.flippers.up() | |
tux.flippers.down() | |
tux.button.remote.registerEventOnPressed(on_standby, K_STANDBY) | |
gtk.gdk.threads_init() | |
gtk.main() | |
tux.access.release() | |
tux.server.disconnect() | |
tux.destroy() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment