Created
July 5, 2013 19:29
-
-
Save swapi/5936687 to your computer and use it in GitHub Desktop.
VLC Remote Control for Pebble Watch
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
#Dependency: | |
#-libpebble with other required libs (e.g. lightblue etc) | |
#-py-vlcclient (https://github.com/DerMitch/py-vlcclient.git) | |
#it is assumed that pebble is already paired. | |
from vlcclient import VLCClient | |
import pebble as libpebble | |
import sys | |
import time | |
vlc_host = "localhost" | |
pebble_id = '<pebble-id>' | |
lightblue = True | |
pair = False | |
try: | |
vlc = VLCClient(vlc_host) | |
vlc.connect() | |
except: | |
print("Cannot connect to vlc instance, check whether vlc is running or telnet interface is enabled") | |
print("Error: " + str(sys.exc_info())) | |
exit(1) | |
try: | |
pebble = libpebble.Pebble(pebble_id, using_lightblue=lightblue, pair_first=pair) | |
except: | |
vlc.disconnect(); | |
print("Cannot connect to pebble, check whether bluetooth is enabled in here and pebble") | |
print("Error: " + str(sys.exc_info())) | |
exit(1) | |
state = "stopped" | |
def update_metadata(): | |
global state | |
status = vlc.status() | |
if len(status.split(')')) > 3: | |
movie = status.split(')')[0].split(':')[-1].split('/')[-1] | |
volume = status.split(')')[1].split(':')[-1] | |
#bug in vlc/vlc-client, not correct status is returned, rely manual status | |
#change in control_vlc() function | |
#state = vlc.status().split(')')[2].split(':')[-1].split(' ')[-2] | |
pebble.set_nowplaying_metadata(movie, 'Volume:' + volume, 'VLC ' + state) | |
else: | |
state = "stopped" | |
pebble.set_nowplaying_metadata("No movie is playing", "", "VLC Player") | |
def control_vlc(event): | |
global state | |
if event == "playpause": | |
if state == "paused": | |
vlc.play() | |
state = "playing" | |
elif state == "playing": | |
vlc.pause() | |
state = "paused" | |
if event == "ff": | |
vlc.fastforward() | |
if event == "rew": | |
vlc.rewind() | |
def vlc_control_handler(endpoint, resp): | |
events = { | |
"PLAYPAUSE": "playpause", | |
"PREVIOUS": "rew", | |
"NEXT": "ff" | |
} | |
control_vlc(events[resp]) | |
update_metadata() | |
state = vlc.status().split(')')[2].split(':')[-1].split(' ')[-2] | |
update_metadata() | |
pebble.register_endpoint("MUSIC_CONTROL", vlc_control_handler) | |
print 'waiting for vlc control events' | |
try: | |
while True: | |
update_metadata() | |
time.sleep(5) | |
except: | |
vlc.disconnect() | |
pebble.disconnect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment