1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2010 Thomas Perl and the gPodder Team
6 # gPodder is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # gpodder.player - Podcatcher implementation of the Media Player D-Bus API
22 # Thomas Perl <thp@gpodder.org>; 2010-04-25
24 # Specification: http://gpodder.org/wiki/Media_Player_D-Bus_API
31 # Import Mock D-Bus interfaces when D-Bus bindings are not installed
32 from gpodder
.gui
import dbus
35 class MediaPlayerDBusReceiver(object):
36 INTERFACE
= 'org.gpodder.player'
37 SIGNAL_STARTED
= 'PlaybackStarted'
38 SIGNAL_STOPPED
= 'PlaybackStopped'
40 def __init__(self
, on_play_event
):
41 self
.on_play_event
= on_play_event
43 self
.bus
= dbus
.SessionBus()
44 self
.bus
.add_signal_receiver(self
.on_playback_started
, \
45 self
.SIGNAL_STARTED
, \
49 self
.bus
.add_signal_receiver(self
.on_playback_stopped
, \
50 self
.SIGNAL_STOPPED
, \
55 def on_playback_started(self
, position
, file_uri
):
58 def on_playback_stopped(self
, start
, end
, total
, file_uri
):
59 if file_uri
.startswith('/'):
60 file_uri
= 'file://' + file_uri
61 self
.on_play_event(start
, end
, total
, file_uri
)