diff options
Diffstat (limited to 'src/mpris2-controller.vala')
-rw-r--r-- | src/mpris2-controller.vala | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 6fa140e..d5152c2 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -19,6 +19,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. */ using DBus; + [DBus (name = "org.mpris.MediaPlayer2")] public interface MprisRoot : DBus.Object { // properties @@ -89,7 +90,7 @@ public class Mpris2Controller : GLib.Object this.properties_interface.PropertiesChanged += property_changed_cb; } catch (DBus.Error e) { - error("Problems connecting to the session bus - %s", e.message); + error("Problems connecting to the session bus - %s", e.message); } } @@ -118,30 +119,34 @@ public class Mpris2Controller : GLib.Object Value? meta_v = changed_properties.lookup("Metadata"); if(meta_v != null){ - debug("metadata is not empty"); - debug("artist : %s", this.player.Metadata.lookup("artist").get_string()); - debug("arturl: %s", this.player.Metadata.lookup("arturl").get_string()); - /*try{ - debug("arturl : %s", this.player.Metadata.lookup("arturl").get_string()); - } - catch(GLib.Error e){ - warning("NO ART URL"); - }*/ + GLib.HashTable<string, Value?> changed_updates = clean_metadata(); + + MetadataMenuitem meta = this.owner.custom_items[PlayerController.widget_order.METADATA] as MetadataMenuitem; + meta.reset(MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); - debug("After the reset the arturl = %i", this.owner.custom_items[PlayerController.widget_order.METADATA].property_get_int("x-canonical-sound-menu-player-metadata-arturl")); - this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata, + this.owner.custom_items[PlayerController.widget_order.METADATA].update(changed_updates, MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); - if((int)this.player.Metadata.lookup("artist").get_string().len() > 0 || - (int)this.player.Metadata.lookup("title").get_string().len() > 0){ - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata, - ScrubMenuitem.attributes_format()); - } + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(changed_updates, + ScrubMenuitem.attributes_format()); + (this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_playstate(this.determine_play_state(this.player.PlaybackStatus)); } } + + private GLib.HashTable<string, Value?> clean_metadata() + { + GLib.HashTable<string, Value?> changed_updates = this.player.Metadata; + string[] artists = (string[])this.player.Metadata.lookup("xesam:artist"); + string display_artists = string.joinv(", ", artists); + changed_updates.replace("xesam:artist", display_artists); + debug("artist : %s", display_artists); + int64 duration = this.player.Metadata.lookup("mpris:length").get_int64(); + changed_updates.replace("mpris:length", duration/1000000); + return changed_updates; + } + private int determine_play_state(string status){ if(status == null) @@ -166,9 +171,10 @@ public class Mpris2Controller : GLib.Object debug("initial update - play state %i", status); (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(status); - this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata, + var cleaned_metadata = this.clean_metadata(); + this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata, MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata, + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(cleaned_metadata, ScrubMenuitem.attributes_format()); } @@ -211,19 +217,18 @@ public class Mpris2Controller : GLib.Object public void set_position(double position) { debug("Set position with pos (0-100) %f", position); - HashTable<string, Value?> data = this.player.Metadata; - Value? time_value = data.lookup("time"); + Value? time_value = this.player.Metadata.lookup("mpris:length"); if(time_value == null){ warning("Can't fetch the duration of the track therefore cant set the position"); return; } // work in microseconds (scale up by 10 TTP-of 6) - uint32 total_time = time_value.get_uint() * 1000000; + int64 total_time = time_value.get_int64(); debug("total time of track = %i", (int)total_time); double new_time_position = total_time * (position/100.0); debug("new position = %f", (new_time_position)); - Value? v = this.player.Metadata.lookup("trackid"); + Value? v = this.player.Metadata.lookup("mpris:trackid"); if(v != null){ if(v.holds (typeof (string))){ DBus.ObjectPath path = new ObjectPath(v.get_string()); |