2 * Copyright (C) 2008 OpenedHand Ltd.
3 * Copyright (C) 2009 Nokia Corporation.
5 * Author: Jorn Baayen <jorn@openedhand.com>
6 * Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
7 * <zeeshan.ali@nokia.com>
9 * Rygel is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Rygel is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 using Rygel.MPRIS.MediaPlayer;
28 public class Rygel.MPRIS.Player : GLib.Object, Rygel.MediaPlayer {
29 private string[] protocols;
30 private string[] mime_types;
32 private PlayerProxy actual_player;
33 private Properties properties;
35 public string playback_state {
37 return this.mpris_to_upnp_state (actual_player.playback_status);
41 debug ("Changing playback state to %s..", value);
43 /* FIXME: Do something about errors below */
47 this.actual_player.stop ();
48 } catch (Error error) {}
51 case "PAUSED_PLAYBACK":
53 this.actual_player.pause ();
54 } catch (Error error) {}
59 this.actual_player.play ();
60 } catch (Error error) {}
64 assert_not_reached ();
71 var val = this.actual_player.metadata.lookup ("xesam:url");
82 this.actual_player.open_uri (value);
83 } catch (Error error) {}
87 public double volume {
89 return this.actual_player.volume;
93 this.actual_player.volume = value;
97 public int64 duration {
99 var val = this.actual_player.metadata.lookup ("mpris:length");
103 dur = (int64) val * 1000;
110 public int64 position {
112 return this.actual_player.position * 1000;
116 public Player (PlayerProxy actual_player,
117 Properties properties,
119 string[] protocols) {
120 this.actual_player = actual_player;
121 this.properties = properties;
122 this.mime_types = mime_types;
123 this.protocols = protocols;
125 this.properties.properties_changed.connect (this.on_properties_changed);
128 public bool seek (Gst.ClockTime time) {
132 this.actual_player.seek (time / 1000);
134 } catch (Error error) {}
139 public string[] get_protocols () {
140 return this.protocols;
143 public string[] get_mime_types () {
144 return this.mime_types;
147 private string mpris_to_upnp_state (string state) {
152 return "PAUSED_PLAYBACK";
156 assert_not_reached ();
160 private void on_properties_changed (string iface,
161 HashTable<string,Variant> changed,
162 string[] invalidated) {
163 if (changed.lookup ("PlaybackStatus") != null) {
164 this.notify_property ("playback-state");
167 if (changed.lookup ("Volume") != null) {
168 this.notify_property ("volume");
171 if (changed.lookup ("Metadata") != null) {
172 var metadata = this.actual_player.metadata;
174 if (metadata.lookup ("xesam:url") != null) {
175 this.notify_property ("uri");
178 if (metadata.lookup ("mpris:length") != null) {
179 this.notify_property ("duration");