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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
<?php
/*
Copyright (c) 2001 - 2006 Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
class Localplay {
/* Base Variables */
/* Built Variables */
var $_function_map = array();
var $_template;
var $_preferences = array();
var $_player;
/**
* Constructor
* This must be called with a localplay type, it then loads the config
* file for the specified type and attempts to load in the function
* map, the preferences and the template
*/
function Localplay($type) {
$this->type = $type;
$this->_get_info();
/* Test for a connection */
$this->connect();
} // Localplay
/**
* _get_info
* This functions takes the type and attempts to get all the
* information needed to load it. Will log errors if there are
* any failures, fatal errors will actually return something to the
* gui
*/
function _get_info() {
$this->_load_player();
} // _get_info
/**
* _load_player
* This function attempts to load the player class that localplay
* Will interface with in order to make all this magical stuf work
* all LocalPlay modules should be located in /modules/<name>/<name>.class.php
*/
function _load_player() {
$filename = conf('prefix') . '/modules/localplay/' . $this->type . '.controller.php';
$include = require_once ($filename);
if (!$include) {
/* Throw Error Here */
} // include
else {
$class_name = "Ampache" . $this->type;
$this->_player = new $class_name();
$function_map = $this->_player->function_map();
$this->_map_functions($function_map);
}
} // _load_player
/**
* has_function
* This is used to check the function map and see if the current
* player type supports the indicated function.
*/
function has_function($function_name) {
/* Check the function map, if it's got a value it must
* be possible
*/
if (strlen($this->_function_map) > 0) { return true; }
return false;
} // has_function
/**
* _map_functions
* This takes the results from the loaded from the target player
* and maps them to the defined functions that Ampache currently
* supports, this is broken into require and optional componets
* Failure of required componets will cause log entry and gui
* warning. The value of the elements in the $data array should
* be function names that are called on the action in question
*/
function _map_functions($data) {
/* Required Functions */
$this->_function_map['add'] = $data['add'];
$this->_function_map['delete'] = $data['delete'];
$this->_function_map['play'] = $data['play'];
$this->_function_map['stop'] = $data['stop'];
$this->_function_map['connect'] = $data['connect'];
/* Recommended Functions */
$this->_function_map['next'] = $data['next'];
$this->_function_map['prev'] = $data['prev'];
$this->_function_map['get_playlist'] = $data['get_playlist'];
$this->_function_map['get_playing'] = $data['get_playing'];
/* Optional Functions */
$this->_function_map['volume_set'] = $data['volume_set'];
$this->_function_map['volume_up'] = $data['volume_up'];
$this->_function_map['volume_down'] = $data['volume_down'];
} // _map_functions
/**
* connect
* This function attempts to connect to the localplay
* player that we are using
*/
function connect() {
$function = $this->_function_map['connect'];
if (!$this->_player->$function()) {
debug_event('localplay','Error Unable to connect, check ' . $this->type . ' controller','1');
return false;
}
return true;
} // connect
/**
* play
* This function passes NULL and calls the play function of the player
* object
*/
function play() {
$function = $this->_function_map['play'];
if (!$this->_player->$function()) {
debug_event('localplay','Error Unable to start playback, check ' . $this->type . ' controller','1');
return false;
}
return true;
} // play
/**
* stop
* This functions passes NULl and calls the stop function of the player
* object, it should recieve a true/false boolean value
*/
function stop() {
$function = $this->_function_map['stop'];
if (!$this->_player->$function()) {
debug_event('localplay','Error Unable to stop playback, check ' . $this->type . ' controller','1');
return false;
}
return true;
} // stop
/**
* add
* This function takes an array of song_ids and then passes the full URL
* to the player, this is a required function.
*/
function add($songs) {
/* Call the Function Specified in the Function Map */
} // add
} //end localplay class
?>
|