Guest User

Untitled

a guest
Jun 5th, 2015
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. import gi
  2. import ipdb
  3. import evdev
  4. from itertools import cycle
  5. gi.require_version('Gst', '1.0')
  6. from gi.repository import GObject, Gst
  7.  
  8. # You should call GObject.threads_init() in your module-scope,
  9. # right after your imports. Unlike the static bindings, you also need to call
  10. # Gst.init()
  11. GObject.threads_init()
  12. Gst.init(None)
  13.  
  14. # Grab user keyboard
  15. USER_KEYBOARD = evdev.InputDevice('/dev/input/event2')
  16.  
  17. with open("radio_stations.txt") as f:
  18.     MUSIC_STREAM_URI = f.readlines()   
  19.  
  20. # To cycle
  21. MUSIC_STREAM_URI = cycle(MUSIC_STREAM_URI)
  22.  
  23. def change_state_player(Player):
  24.     if Player.get_state(0)[1] == Gst.State.PAUSED:
  25.         Player.set_state(Gst.State.PLAYING)
  26.     else:
  27.         Player.set_state(Gst.State.PAUSED)
  28.  
  29. def next_radiostation(Player):
  30.     Player.set_state(Gst.State.READY)
  31.     Player.set_property('uri', next(MUSIC_STREAM_URI))
  32.     Player.set_state(Gst.State.PLAYING)
  33.  
  34.  
  35. # Create a player object
  36. player = Gst.ElementFactory.make("playbin", "player")
  37.  
  38. # Play first radiostation from list
  39. next_radiostation(player)
  40.  
  41. for event in USER_KEYBOARD.read_loop():
  42.     if event.type == evdev.ecodes.EV_KEY:
  43.         event_data = evdev.categorize(event)
  44.  
  45.         # If user PRESS PLAY/PAUSE button, we PLAY/PAUSE player
  46.         if event_data.scancode == 164 and event_data.keystate == 0x01:
  47.             change_state_player(player)
  48.  
  49.         # If user PRESS NEXT button
  50.         if event_data.scancode == 163 and event_data.keystate == 0x01:
  51.             next_radiostation(player)
Advertisement
Add Comment
Please, Sign In to add comment