1 # -*- coding: utf-8 -*-
3 # ****************************************************************************
4 # Copyright (c) 2008 INdT/Fucapi.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program 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
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # ============================================================================
19 # Project Name : PC Remote
20 # Author : Jonatas Isvi
21 # Email : jonatas.nona@gmail.com
26 # Description : Amarok Player
27 # ============================================================================
32 from playlist import Playlist
37 return commands.getoutput(command)
40 # starts the amarok player application
45 # close the amarok player application
47 shell('dcop amarok player stop')
48 pid = shell('pidof amarokapp')
49 shell('kill -9 %s' % pid)
52 # verifies if the amarok is running
54 pid = shell('pidof amarokapp')
60 def send_file(addr, path):
61 shell("bluetooth-sendto --dest=%s %s" + (addr, path))
66 Define all states and functions of amarok player.
67 This class will build to support PCRemote Player,
68 receiving messages from any devices with a bluetooth
72 # some importants variables
74 self.amarok = pydcop.anyAppCalled("amarok")
75 self.playlist = Playlist(self.amarok.playlist.saveCurrentPlaylist())
78 # refresh playlist, accessing the Playlist class instance
79 def refresh_playlist(self):
80 self.playlist = Playlist(self.amarok.playlist.saveCurrentPlaylist())
83 # get all songs of playlist
87 # show current song, acessing the Playlist class instance
88 def current_song(self):
91 # verifies if this amarok app is running
93 aux = pydcop.anyAppCalled("amarok")
99 # verifies if this amarok app is playing and update the
100 # Playlist with current song
102 if not self.amarok.player.isPlaying() == 'true':
103 self.playlist.update(self.amarok.playlist.getActiveIndex(),\
104 self.amarok.player.title(), \
105 self.amarok.player.artist(), \
106 self.amarok.player.path(), \
107 "." + self.amarok.player.type(), \
113 # get the players name
117 # send audio files to the N810 device
118 def file_properties(self, index=None):
119 track = self.amarok.playlist.getActiveIndex()
120 audiofile = self.playlist.song_properties(index=track, path=True)
121 #audiofile = (self.playlist.song_filename(index),\
122 # self.playlist.song_size(index))
125 # next button and sets current song
127 self.amarok.player.next()
128 self.playlist.update(self.amarok.playlist.getActiveIndex(),\
129 self.amarok.player.title(), \
130 self.amarok.player.artist(), \
131 self.amarok.player.path(), \
132 "." + self.amarok.player.type(), \
135 # prev button and sets current song
137 self.amarok.player.prev()
138 self.playlist.update(self.amarok.playlist.getActiveIndex(),\
139 self.amarok.player.title(), \
140 self.amarok.player.artist(), \
141 self.amarok.player.path(), \
142 "." + self.amarok.player.type(), \
145 # play button and sets current song
147 #self.amarok.player.play()
148 #self.playlist.update(self.amarok.playlist.getActiveIndex() + 1,\
149 # self.amarok.player.title(), \
150 # self.amarok.player.artist(), \
151 # self.amarok.player.path(), \
152 # "." + self.amarok.player.type(), \
155 # play button and sets current song
156 # receive track or random form
157 # the argument track has intended to manipulate
158 # the playlist form when the user indicate a song track
159 # in client application
160 def play(self, track=-1, rdm=False):
162 index = random.randint(0, self.playlist.length() - 1)
163 self.amarok.playlist.playByIndex(index)
164 self.playlist.update(index + 1, \
165 self.amarok.player.title(), \
166 self.amarok.player.artist(), \
167 self.amarok.player.path(), \
168 "." + self.amarok.player.type(),\
171 self.amarok.playlist.playByIndex(track)
172 self.playlist.update(track-1, \
173 self.amarok.player.title(), \
174 self.amarok.player.artist(), \
175 self.amarok.player.path(), \
176 "." + self.amarok.player.type(),\
179 self.amarok.player.play()
180 self.playlist.update(self.amarok.playlist.getActiveIndex() + 1,\
181 self.amarok.player.title(), \
182 self.amarok.player.artist(), \
183 self.amarok.player.path(), \
184 "." + self.amarok.player.type(), \
187 # play button with index song and sets current song
188 #def play_track(self, index):
189 # self.amarok.playlist.playByIndex(index-1)
190 # self.playlist.update(index, \
191 # self.amarok.player.title(), \
192 # self.amarok.player.artist(), \
193 # self.amarok.player.path(), \
194 # "." + self.amarok.player.type(),\
198 #def play_random(self):
199 # index = random.randint(0, self.playlist.length() - 1)
200 # self.amarok.playlist.playByIndex(index)
201 # self.playlist.update(index+1, \
202 # self.amarok.player.title(), \
203 # self.amarok.player.artist(), \
204 # self.amarok.player.path(), \
205 # "." + self.amarok.player.type(),\
210 self.amarok.player.pause()
214 self.amarok.player.mute()
218 self.amarok.player.stop()
220 # get the current volume value
221 def get_volume(self):
222 return self.amarok.player.getVolume()
225 def volume_up(self, increase=1):
226 if (self.get_volume() + increase) <= 100:
227 up = self.get_volume() + increase
228 self.amarok.player.setVolume(up)
233 def volume_down(self, decrement=1):
234 if (self.get_volume() - decrement) >= 0:
235 down = self.get_volume() - decrement
236 self.amarok.player.setVolume(down)
241 def seek(self, value):
242 self.amarok.player.seek(value)