1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#!/usr/bin/env python
# XMMS2 - X Music Multiplexer System
# Copyright (C) 2003-2006 XMMS2 Team
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# This file is a part of the XMMS2 client tutorial #2
# Here we will learn to retrieve results from a command
import xmmsclient
import os
import sys
"""
The first part of this program is
commented in tut1.py See that one for
instructions
"""
xmms = xmmsclient.XMMS("tutorial2")
try:
xmms.connect(os.getenv("XMMS_PATH"))
except IOError, detail:
print "Connection failed:", detail
sys.exit(1)
"""
Now we send a command that will return
a result. Let's find out which entry
is currently playing.
Note that this program has be run while
xmms2 is playing something, otherwise
XMMS.playback_current_id will return 0.
"""
result = xmms.playback_current_id()
"""
We are still doing sync operations, wait for the
answer and block.
"""
result.wait()
"""
Also this time we need to check for errors.
Errors can occur on all commands, but not signals
and broadcasts. We will talk about these later.
"""
if result.iserror():
print "playback current id returns error, %s" % result.get_error()
"""
Let's retrieve the value from the XMMSResult object.
You don't have to know what type of value is returned
in response to which command - simply call
XMMSResult.value()
In this case XMMS.playback_current_id will return a UINT
"""
id = result.value()
"""Print the value"""
print "Currently playing id is %d" % id
|