1
/* XMMS2 - X Music Multiplexer System
2
* Copyright (C) 2003-2006 XMMS2 Team
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* This file is a part of the XMMS2 client tutorial #2
17
#include <xmmsclient/xmmsclient++.h>
26
Xmms::Client client("tutorial2");
29
* You might've noticed from the previous tutorial
30
* that there wasn't very much error handling involved.
31
* Well, it's not really that simple, most
32
* functions throw three kinds of exceptions,
34
* - Xmms::connection_error
35
* - Thrown when the client can't connect()
36
* or if the client is disconnected.
38
* - Xmms::result_error
39
* - Thrown if there was an error getting a
40
* result from the server.
42
* - Xmms::mainloop_running_error
43
* - (a logic_error) Thrown if the mainloop
44
* is running and program calls a synchronized
45
* function (a bad thing). Shouldn't be caught.
47
* All exceptions are derived from std::runtime_error, except
48
* the mainloop_running_error, which is std::logic_error.
49
* (A C++ coder should know what this means basically,
50
* go learn if you don't.)
55
client.connect( std::getenv( "XMMS_PATH" ) );
59
* Connection might fail and if it does, it will throw
60
* an Xmms::connection_error.
62
* As every good C++ coder knows, always catch exceptions by reference.
64
catch( Xmms::connection_error& err ) {
66
std::cout << "Connection failed: " << err.what() << std::endl;
69
* If we don't quit here, all functions will fail with the
79
* To fetch the current playing id we use this method.
80
* Xmms::Playback::currentID() (and all others) actually
81
* returns a special class which implicitly converts to
82
* the appropriate type in synchronous mode. This will
83
* be handled in detail in later tutorials.
85
int id = client.playback.currentID();
86
std::cout << "Currently playing ID is " << id << std::endl;
90
* As mentioned earlier, all other methods sync methods
91
* (except Xmms::Client::connect and Xmms::Client::quit)
92
* will throw Xmms::result_error if an error occurs.
94
catch( Xmms::result_error& err ) {
96
std::cout << "playback start returned error, "
97
<< err.what() << std::endl;
103
* Error handling with asynchronous client and
104
* more complex types will be commented on later.