~ubuntu-branches/ubuntu/saucy/xmms2/saucy-proposed

« back to all changes in this revision

Viewing changes to doc/tutorial/python/tut2.py

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2011-10-22 23:53:00 UTC
  • mto: (38.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 43.
  • Revision ID: james.westby@ubuntu.com-20111022235300-u50pdo3g341jvk7q
ImportĀ upstreamĀ versionĀ 0.8+dfsg

Show diffs side-by-side

added added

removed removed

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