--- /dev/null
+# -*- coding: utf-8 -*-
+
+# ****************************************************************************
+# Copyright (c) 2008 INdT/Fucapi.
+# This program 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 3 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 Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# ============================================================================
+# Project Name : PC Remote
+# Author : Jonatas Isvi
+# Email : jonatas.nona@gmail.com
+# Reviewer :
+# Email :
+# Version : 1.0
+# Packge : players
+# Description : Amarok Player
+# ============================================================================
+
+import os
+import commands
+import random
+from playlist import Playlist
+import pydcop
+
+# command line
+def shell(command):
+ return commands.getoutput(command)
+
+# starts the amarok player application
+def start():
+ os.popen('amarok')
+
+# close the amarok player application
+def shutdown():
+ shell('dcop amarok player stop')
+ pid = shell('pidof amarokapp')
+ shell('kill -9 %s' % pid)
+
+# verifies if the amarok is running
+def isRunning():
+ pid = shell('pidof amarokapp')
+ if pid > 0:
+ return True
+ else:
+ return False
+
+class AmarokPlayer():
+
+ """ Amarok
+ Define all states and functions of amarok player.
+ This class will build to support PCRemote Player,
+ receiving messages from any devices with a bluetooth
+ connection.
+ """
+
+ # some importants variables
+ def __init__(self):
+ self.amarok = pydcop.anyAppCalled("amarok")
+ self.playlist = Playlist(self.amarok.playlist.saveCurrentPlaylist())
+ self.isPlaying()
+
+ # refresh playlist, accessing the Playlist class instance
+ def refresh_playlist(self):
+ self.playlist = Playlist(self.amarok.playlist.saveCurrentPlaylist())
+ self.isPlaying()
+
+ # get all songs of playlist
+ def song_list(self):
+ self.playlist.show()
+
+ # show current song, acessing the Playlist class instance
+ def current_song(self):
+ self.isPlaying()
+
+ # verifies if this amarok app is running
+ def isRunning(self):
+ aux = pydcop.anyAppCalled("amarok")
+ if aux:
+ return aux
+ else:
+ return None
+
+ # verifies if this amarok app is playing and update the
+ # Playlist with current song
+ def isPlaying(self):
+ if not self.amarok.player.isPlaying() == 'true':
+ self.playlist.update(self.amarok.playlist.getActiveIndex() + 1,\
+ self.amarok.player.title(), \
+ self.amarok.player.artist(), \
+ self.amarok.player.path(), \
+ "." + self.amarok.player.type(), \
+ )
+ return True
+ else:
+ return False
+
+ # get the players name
+ def getName(self):
+ return "Amarok"
+
+ # send audio files to the N810 device
+ def audio_file_properties(self, index=None):
+ audiofile = (self.playlist.song_filename(index),\
+ self.playlist.song_size(index))
+ return audiofile
+
+ # next button and sets current song
+ def next(self):
+ self.amarok.player.next()
+ self.playlist.update(self.amarok.playlist.getActiveIndex() + 1,\
+ self.amarok.player.title(), \
+ self.amarok.player.artist(), \
+ self.amarok.player.path(), \
+ "." + self.amarok.player.type(), \
+ )
+
+ # prev button and sets current song
+ def prev(self):
+ self.amarok.player.prev()
+ self.playlist.update(self.amarok.playlist.getActiveIndex() + 1,\
+ self.amarok.player.title(), \
+ self.amarok.player.artist(), \
+ self.amarok.player.path(), \
+ "." + self.amarok.player.type(), \
+ )
+
+ # play button and sets current song
+ def play(self):
+ self.amarok.player.play()
+ self.playlist.update(self.amarok.playlist.getActiveIndex() + 1,\
+ self.amarok.player.title(), \
+ self.amarok.player.artist(), \
+ self.amarok.player.path(), \
+ "." + self.amarok.player.type(), \
+ )
+
+ # play button with index song and sets current song
+ def play_track(self, index):
+ self.amarok.playlist.playByIndex(index-1)
+ self.playlist.update(index, \
+ self.amarok.player.title(), \
+ self.amarok.player.artist(), \
+ self.amarok.player.path(), \
+ "." + self.amarok.player.type(),\
+ )
+
+ # random play songs
+ def play_random(self):
+ index = random.randint(0, self.playlist.length() - 1)
+ self.amarok.playlist.playByIndex(index)
+ self.playlist.update(index+1, \
+ self.amarok.player.title(), \
+ self.amarok.player.artist(), \
+ self.amarok.player.path(), \
+ "." + self.amarok.player.type(),\
+ )
+
+ # pause button
+ def pause(self):
+ self.amarok.player.pause()
+
+ # mute button
+ def mute(self):
+ self.amarok.player.mute()
+
+ # stop button
+ def stop(self):
+ self.amarok.player.stop()
+
+ # get the current volume value
+ def get_volume(self):
+ return self.amarok.player.getVolume()
+
+ # set up volume
+ def volume_up(self, increase=1):
+ if (self.get_volume() + increase) <= 100:
+ up = self.get_volume() + increase
+ self.amarok.player.setVolume(up)
+ else:
+ print "erro!"
+
+ # set down volume
+ def volume_down(self, decrement=1):
+ if (self.get_volume() - decrement) >= 0:
+ down = self.get_volume() - decrement
+ self.amarok.player.setVolume(down)
+ else:
+ print "erro!"
+
+ # set seek value
+ def seek(self, value):
+ self.amarok.player.seek(value)