Created
October 29, 2011 20:40
-
-
Save son-link/1325063 to your computer and use it in GitHub Desktop.
Adeskbar plugin for play CD-Audio
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
Español: | |
Descarga cdaudio.py a una carpeta y y busca la siguiente linea: | |
device = '/dev/sr1' | |
Cambia el valor por la ruta al dispositivo de tu lector de cd/dvd (suele ser /dev/cdromX o /dev/srX donde X es un valor numérico, si solo tienes un dispositivo de CD/DVD entones X valdrá 0 ) y muevelo a /usr/share/adeskbar/plugins. | |
Una vez movido edita el archivo /usr/share/adeskbar/plugins/__init__py (necesitas permisos de root) y al final del todo añade las siguientes lineas: | |
info['cdplay'] = { | |
'desc':'CD Audio Player', | |
'icon':'images/plugins/volume.png', | |
} | |
Reinicia Adeskbar y lo podrás añadir como al resto de plugins |
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/python2 | |
# -*- coding: utf-8 -*- | |
# CD Audio player plugin for Adeskbar 0.2.0 | |
# (c) 2011 Alfonso Saavedra "Son Link" | |
# Under GPLv3 License | |
import pygst | |
pygst.require("0.10") | |
import gst | |
import gobject, gtk | |
import sys, thread, time | |
import adesk.plugin as Plg | |
from os import system | |
device = '/dev/sr1' | |
class Plugin(Plg.PluginContainer): | |
def __init__(self, bar, settings): | |
Plg.PluginContainer.__init__(self, bar, settings) | |
self.can_zoom = False | |
self.can_show_icon = False | |
self.settings = settings | |
self.bar = bar | |
self.locked = False | |
self.actual_track = 1 | |
self.status = -1 | |
# -1 -> No hace nada, 0 Stop, 1 play, 2 pause | |
self.box = gtk.VBox(False, 0) | |
self.box.set_border_width(5) | |
infobox = gtk.HBox() | |
infobox.set_spacing(5) | |
self.spinner = gtk.Spinner() | |
infobox.pack_start(self.spinner, False, False, 0) | |
self.info = gtk.Label(str='Pista 00 de 00') | |
#self.info.set_alignment(1, 0) | |
infobox.pack_end(self.info, False, False, 0) | |
self.box.pack_start(infobox, False, False, 0) | |
hbox = gtk.HBox() | |
self.box.add(hbox) | |
# Prev button | |
prev_eventbox = gtk.EventBox() | |
prev_eventbox.connect('button-press-event', self.prev) | |
prev_img = gtk.image_new_from_stock(gtk.STOCK_MEDIA_PREVIOUS, gtk.ICON_SIZE_SMALL_TOOLBAR) | |
prev_eventbox.add(prev_img) | |
hbox.add(prev_eventbox) | |
# Play button | |
self.play_eventbox = gtk.EventBox() | |
self.play_img = gtk.image_new_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_SMALL_TOOLBAR) | |
self.play_eventbox.connect('button-press-event', self.play) | |
self.play_eventbox.add(self.play_img) | |
hbox.add(self.play_eventbox) | |
# Stop button | |
stop_eventbox = gtk.EventBox() | |
stop_img = gtk.image_new_from_stock(gtk.STOCK_MEDIA_STOP, gtk.ICON_SIZE_SMALL_TOOLBAR) | |
stop_eventbox.connect('button-press-event', self.stop) | |
stop_eventbox.add(stop_img) | |
hbox.add(stop_eventbox) | |
# Next button | |
next_eventbox = gtk.EventBox() | |
next_img = gtk.image_new_from_stock(gtk.STOCK_MEDIA_NEXT, gtk.ICON_SIZE_SMALL_TOOLBAR) | |
next_eventbox.connect('button-press-event', self.next) | |
next_eventbox.add(next_img) | |
hbox.add(next_eventbox) | |
# Eject button | |
eject_eventbox = gtk.EventBox() | |
eject_img = gtk.image_new_from_stock(gtk.STOCK_GOTO_TOP, gtk.ICON_SIZE_SMALL_TOOLBAR) | |
eject_eventbox.connect('button-press-event', self.eject) | |
eject_eventbox.add(eject_img) | |
hbox.add(eject_eventbox) | |
# Volume | |
volume_button = gtk.VolumeButton() | |
volume_button.set_value(1.0) | |
volume_button.connect('value_changed', self.volume) | |
hbox.add(volume_button) | |
self.add(self.box) | |
self.show_all() | |
def play(self, w, *args): | |
if self.status == 1: | |
self.pipeline.set_state(gst.STATE_PAUSED) | |
self.play_eventbox.remove(self.play_img) | |
self.play_img = gtk.image_new_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_SMALL_TOOLBAR) | |
self.play_img.show() | |
self.play_eventbox.add(self.play_img) | |
self.spinner.stop() | |
self.status = 2 | |
elif self.status == 2: | |
self.play_eventbox.remove(self.play_img) | |
self.play_img = gtk.image_new_from_stock(gtk.STOCK_MEDIA_PAUSE, gtk.ICON_SIZE_SMALL_TOOLBAR) | |
self.pipeline.set_state(gst.STATE_PLAYING) | |
self.play_img.show() | |
self.play_eventbox.add(self.play_img) | |
self.spinner.start() | |
self.status = 1 | |
else: | |
self.create_pipeline() | |
self.play_eventbox.remove(self.play_img) | |
self.play_img = gtk.image_new_from_stock(gtk.STOCK_MEDIA_PAUSE, gtk.ICON_SIZE_SMALL_TOOLBAR) | |
self.play_img.show() | |
self.play_eventbox.add(self.play_img) | |
self.pipeline.set_state(gst.STATE_PLAYING) | |
self.spinner.start() | |
self.status = 1 | |
def prev(self, w, *args): | |
if self.actual_track > 1: | |
self.actual_track -= 1 | |
self.pipeline.set_state(gst.STATE_READY) | |
self.pipeline.get_by_name("cdda").set_property("track", self.actual_track) | |
self.pipeline.set_state(gst.STATE_PLAYING) | |
self.update_info() | |
def stop(self, *args): | |
self.play_eventbox.remove(self.play_img) | |
self.play_img = gtk.image_new_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_SMALL_TOOLBAR) | |
self.play_img.show() | |
self.play_eventbox.add(self.play_img) | |
try: | |
self.pipeline.set_state(gst.STATE_NULL) | |
except: | |
pass | |
self.spinner.stop() | |
self.status = 0 | |
def next(self, w, *args): | |
if self.actual_track < self.file_tags['track-count']: | |
self.actual_track += 1 | |
else: | |
self.actual_track = 1 | |
self.pipeline.set_state(gst.STATE_READY) | |
self.pipeline.get_by_name("cdda").set_property("track", self.actual_track) | |
self.pipeline.set_state(gst.STATE_PLAYING) | |
self.update_info() | |
def eject(self, w, *args): | |
self.stop() | |
system('eject '+ device) | |
def create_pipeline(self): | |
cdsrc = 'cdparanoiasrc device=%s track=%i name=cdda ! audioconvert ! volume name=volume ! alsasink' % (device, self.actual_track) | |
self.pipeline = gst.parse_launch(cdsrc) | |
bus = self.pipeline.get_bus() | |
bus.add_signal_watch() | |
bus.connect("message::tag", self.bus_message_tag) | |
bus.connect("message::error", self.bus_message_error) | |
bus.connect("message::eos", self.next) | |
def bus_message_error(self, bus, message): | |
e, d = message.parse_error() | |
print "ERROR:", e | |
def bus_message_tag(self, bus, message): | |
"""Esta es la función encargada de recoger los datos del bus de Gstreamer, principalmente los tags de los ficheros de audio""" | |
self.file_tags = {} | |
taglist = message.parse_tag() | |
for key in taglist.keys(): | |
try: | |
self.file_tags[key] = taglist[key] | |
except: | |
return False | |
self.update_info() | |
def update_info(self): | |
if self.actual_track < 10: | |
track = '0'+str(self.actual_track) | |
else: | |
track = str(self.actual_track) | |
if self.file_tags['track-count'] < 10: | |
total_tracks = '0'+str(self.file_tags['track-count']) | |
else: | |
total_tracks = str(self.file_tags['track-count']) | |
self.info.set_text('Pista ' + track + ' de ' + total_tracks) | |
def volume(self, widget, value): | |
"""Esta función es llamada cada vez que cambie el valor del botón de volumen para cambiar el idem""" | |
self.pipeline.get_by_name("volume").set_property("volume", value) | |
self.volume = value |
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
0.1.0: | |
* primera versión | |
0.2.0: | |
* Añadido botón para expulsar el cd | |
* Se a cambiado el indicador de que pista se esta reproduciendo | |
* Se a añadido un spinner para saber si esta reproduciendo o no |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment