aboutsummaryrefslogtreecommitdiff
path: root/src/mpris2-controller.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/mpris2-controller.vala')
-rw-r--r--src/mpris2-controller.vala57
1 files changed, 39 insertions, 18 deletions
diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala
index d6f27ec..58a1906 100644
--- a/src/mpris2-controller.vala
+++ b/src/mpris2-controller.vala
@@ -30,7 +30,6 @@ public interface FreeDesktopProperties : Object{
*/
public class Mpris2Controller : GLib.Object
{
- public static const string root_interface = "org.mpris.MediaPlayer2" ;
public MprisRoot mpris2_root {get; construct;}
public MprisPlayer player {get; construct;}
public MprisPlaylists playlists {get; construct;}
@@ -46,19 +45,19 @@ public class Mpris2Controller : GLib.Object
construct{
try {
this.mpris2_root = Bus.get_proxy_sync ( BusType.SESSION,
- root_interface.concat(".").concat(this.owner.mpris_name),
- "/org/mpris/MediaPlayer2");
+ this.owner.dbus_name,
+ "/org/mpris/MediaPlayer2" );
this.player = Bus.get_proxy_sync ( BusType.SESSION,
- root_interface.concat(".").concat(this.owner.mpris_name),
+ this.owner.dbus_name,
"/org/mpris/MediaPlayer2" );
this.playlists = Bus.get_proxy_sync ( BusType.SESSION,
- root_interface.concat(".").concat(this.owner.mpris_name),
+ this.owner.dbus_name,
"/org/mpris/MediaPlayer2" );
this.properties_interface = Bus.get_proxy_sync ( BusType.SESSION,
"org.freedesktop.Properties.PropertiesChanged",
- "/org/mpris/MediaPlayer2" );
- this.properties_interface.PropertiesChanged += property_changed_cb;
+ "/org/mpris/MediaPlayer2" );
+ this.properties_interface.PropertiesChanged.connect ( property_changed_cb );
}
catch (IOError e) {
error("Problems connecting to the session bus - %s", e.message);
@@ -69,14 +68,19 @@ public class Mpris2Controller : GLib.Object
HashTable<string, Variant?> changed_properties,
string[] invalid )
{
- debug("properties-changed for interface %s and owner %s", interface_source, this.owner.mpris_name);
- if(changed_properties == null || interface_source.has_prefix(this.root_interface) == false ){
+ debug("properties-changed for interface %s and owner %s", interface_source, this.owner.dbus_name);
+ if ( changed_properties == null ||
+ interface_source.has_prefix ( Mpris2Watcher.MPRIS_PREFIX ) == false ){
warning("Property-changed hash is null or this is an interface that doesn't concerns us");
return;
}
Variant? play_v = changed_properties.lookup("PlaybackStatus");
if(play_v != null){
+ // Race condition sometimes appears with the playback status
+ // 200ms timeout ensures we have the correct playback status at all times.
string state = this.player.PlaybackStatus;
+ //debug("in the property update and the playback status = %s and update = %s", state, (string)play_v);
+ Timeout.add ( 200, ensure_correct_playback_status );
TransportMenuitem.state p = (TransportMenuitem.state)this.determine_play_state(state);
(this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p);
}
@@ -84,7 +88,7 @@ public class Mpris2Controller : GLib.Object
if(meta_v != null){
GLib.HashTable<string, Variant?> changed_updates = clean_metadata();
PlayerItem metadata = this.owner.custom_items[PlayerController.widget_order.METADATA];
- metadata.reset( MetadataMenuitem.attributes_format());
+ metadata.reset ( MetadataMenuitem.attributes_format());
metadata.update ( changed_updates,
MetadataMenuitem.attributes_format());
metadata.property_set_bool ( MENUITEM_PROP_VISIBLE,
@@ -92,11 +96,24 @@ public class Mpris2Controller : GLib.Object
}
Variant? playlist_v = changed_properties.lookup("ActivePlaylist");
if ( playlist_v != null ){
- debug (" WE HAVE PLAYLIST CHANGE EVENT DETECTED ");
this.fetch_active_playlist();
}
}
+ public bool playlist_support()
+ {
+ // awaiting spec updates
+ // return this.mpris2_root.HasPlaylists;
+ return true;
+ }
+
+ private bool ensure_correct_playback_status(){
+ debug("TEST playback status = %s", this.player.PlaybackStatus);
+ TransportMenuitem.state p = (TransportMenuitem.state)this.determine_play_state(this.player.PlaybackStatus);
+ (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p);
+ return false;
+ }
+
private GLib.HashTable<string, Variant?>? clean_metadata()
{
GLib.HashTable<string, Variant?> changed_updates = this.player.Metadata;
@@ -158,34 +175,38 @@ public class Mpris2Controller : GLib.Object
warning("Playlists object is null");
return;
}
- PlaylistDetails[] current_playlists = this.playlists.GetPlaylists(0, 10, "Alphabetical", false);
+ PlaylistDetails[] current_playlists = this.playlists.GetPlaylists(0,
+ 10,
+ "Alphabetical",
+ false);
if( current_playlists != null ){
debug( "Size of the playlist array = %i", current_playlists.length );
PlaylistsMenuitem playlists_item = this.owner.custom_items[PlayerController.widget_order.PLAYLISTS] as PlaylistsMenuitem;
playlists_item.update(current_playlists);
- foreach(PlaylistDetails detail in current_playlists){
+ /*foreach(PlaylistDetails detail in current_playlists){
debug(" \n \n ");
debug( "Playlist Name = %s", detail.name);
debug( "Playlist path = %s", detail.path);
debug( "Playlist icon path = %s", detail.icon_path);
debug(" \n \n ");
- }
+ }*/
}
}
public void fetch_active_playlist()
{
if (this.playlists == null && this.playlists.ActivePlaylist.valid == true){
- warning("Playlists object is null and we have an active playlist");
+ warning("Playlists object is null or we don't have an active playlist");
return;
}
-
- PlaylistDetails active_details = this.playlists.ActivePlaylist.active_playlist;
- debug(" \n \n ");
+ PlaylistsMenuitem playlists_item = this.owner.custom_items[PlayerController.widget_order.PLAYLISTS] as PlaylistsMenuitem;
+ playlists_item.update_active_playlist ( this.playlists.ActivePlaylist.details );
+ /*debug(" \n \n ");
debug( "Active Playlist Name = %s", active_details.name);
debug( "Active Playlist path = %s", active_details.path);
debug( "Active Playlist icon path = %s", active_details.icon_path);
debug(" \n \n ");
+ */
}