106
107
debug("new playback state = %s", state);
107
108
int p = this.determine_play_state(state);
108
109
(this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p);
109
(this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_playstate(p);
112
112
Value? pos_v = changed_properties.lookup("Position");
113
113
if(pos_v != null){
114
114
int64 pos = pos_v.get_int64();
115
115
debug("new position = %i", (int)pos);
116
(this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_position((int32)pos);
119
118
Value? meta_v = changed_properties.lookup("Metadata");
120
119
if(meta_v != null){
121
debug("metadata is not empty");
122
debug("artist : %s", this.player.Metadata.lookup("artist").get_string());
123
this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format());
124
this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata,
120
GLib.HashTable<string, Value?> changed_updates = clean_metadata();
121
this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format());
122
this.owner.custom_items[PlayerController.widget_order.METADATA].update(changed_updates,
125
123
MetadataMenuitem.attributes_format());
126
this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format());
127
if((int)this.player.Metadata.lookup("artist").get_string().len() > 0 ||
128
(int)this.player.Metadata.lookup("artist").get_string().len() > 0){
129
this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata,
130
ScrubMenuitem.attributes_format());
132
(this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_playstate(this.determine_play_state(this.player.PlaybackStatus));
127
private GLib.HashTable<string, Value?> clean_metadata()
129
GLib.HashTable<string, Value?> changed_updates = this.player.Metadata;
130
Value? artist_v = this.player.Metadata.lookup("xesam:artist");
131
if(artist_v != null){
132
string[] artists = (string[])this.player.Metadata.lookup("xesam:artist");
133
string display_artists = string.joinv(", ", artists);
134
changed_updates.replace("xesam:artist", display_artists);
135
debug("artist : %s", display_artists);
137
Value? length_v = this.player.Metadata.lookup("mpris:length");
138
if(length_v != null){
139
int64 duration = this.player.Metadata.lookup("mpris:length").get_int64();
140
changed_updates.replace("mpris:length", duration/1000000);
142
return changed_updates;
137
146
private int determine_play_state(string status){
138
147
if(status == null)
157
166
debug("initial update - play state %i", status);
159
168
(this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(status);
160
this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata,
169
GLib.HashTable<string, Value?> cleaned_metadata = this.clean_metadata();
170
this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata,
161
171
MetadataMenuitem.attributes_format());
162
this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata,
163
ScrubMenuitem.attributes_format());
166
174
public void transport_event(TransportMenuitem.action command)
202
210
public void set_position(double position)
204
212
debug("Set position with pos (0-100) %f", position);
205
HashTable<string, Value?> data = this.player.Metadata;
206
Value? time_value = data.lookup("time");
213
Value? time_value = this.player.Metadata.lookup("mpris:length");
207
214
if(time_value == null){
208
215
warning("Can't fetch the duration of the track therefore cant set the position");
211
// work in microseconds (scale up by 10 TTP-of 3)
212
uint32 total_time = time_value.get_uint() * 1000;
218
// work in microseconds (scale up by 10 TTP-of 6)
219
int64 total_time = time_value.get_int64();
213
220
debug("total time of track = %i", (int)total_time);
214
double new_time_position = total_time * position/100.0;
221
double new_time_position = total_time * (position/100.0);
215
222
debug("new position = %f", (new_time_position));
217
Value? v = this.player.Metadata.lookup("trackid");
224
Value? v = this.player.Metadata.lookup("mpris:trackid");
219
226
if(v.holds (typeof (string))){
220
debug("the trackid = %s", v.get_string());
221
227
DBus.ObjectPath path = new ObjectPath(v.get_string());
223
//this.player.SetPosition(path, (int64)(new_time_position));
229
this.player.SetPosition(path, (int64)(new_time_position));
230
//ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem;
231
//scrub.update_position(((int32)new_time_position) / 1000);
225
233
catch(DBus.Error e){
226
234
error("DBus Error calling the player objects SetPosition method %s",
233
241
public void onSeeked(int64 position){
234
242
debug("Seeked signal callback with pos = %i", (int)position/1000);
235
ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem;
236
scrub.update_position((int32)position/1000);
243
//ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem;
244
//scrub.update_position((int32)position/1000);
239
247
public bool connected()