@@ -152,26 +152,6 @@ static void playerctl_player_set_property(GObject *object, guint property_id, co
152152 org_mpris_media_player2_player_set_volume (self -> priv -> proxy , g_value_get_double (value ));
153153 break ;
154154
155- case PROP_POSITION :
156- {
157- GError * * err = NULL ;
158- // calling the function requires the track id
159- GVariant * metadata = playerctl_player_get_metadata (self , err );
160- if (err != NULL )
161- return ;
162-
163- GVariant * track_id_variant = g_variant_lookup_value (metadata , "mpris:trackid" , G_VARIANT_TYPE_OBJECT_PATH );
164- if (track_id_variant == NULL )
165- return ;
166-
167- const gchar * track_id = g_variant_get_string (track_id_variant , NULL );
168- if (track_id == NULL )
169- return ;
170-
171- org_mpris_media_player2_player_call_set_position_sync (self -> priv -> proxy , track_id , g_value_get_int64 (value ), NULL , NULL );
172- break ;
173- }
174-
175155 default :
176156 G_OBJECT_WARN_INVALID_PROPERTY_ID (object , property_id , pspec );
177157 break ;
@@ -297,7 +277,7 @@ static void playerctl_player_class_init (PlayerctlPlayerClass *klass) {
297277 0 ,
298278 INT64_MAX ,
299279 0 ,
300- G_PARAM_READWRITE );
280+ G_PARAM_READABLE );
301281
302282 obj_properties [PROP_METADATA ] =
303283 g_param_spec_variant ("metadata" ,
@@ -830,3 +810,43 @@ gchar *playerctl_player_get_album(PlayerctlPlayer *self, GError **err)
830810
831811 return playerctl_player_print_metadata_prop (self , "xesam:album" , NULL );
832812}
813+
814+ /**
815+ * playerctl_player_set_position
816+ * @self: a #PlayerctlPlayer
817+ * @err: (allow-none): the location of a GError or NULL
818+ *
819+ * Sets the position of the current track to the given position in microseconds.
820+ */
821+ void playerctl_player_set_position (PlayerctlPlayer * self , gint64 position , GError * * err )
822+ {
823+ GError * tmp_error = NULL ;
824+
825+ g_return_if_fail (err == NULL || * err == NULL );
826+
827+ if (self -> priv -> init_error != NULL ) {
828+ g_propagate_error (err , g_error_copy (self -> priv -> init_error ));
829+ }
830+
831+ // calling the function requires the track id
832+ GVariant * metadata = playerctl_player_get_metadata (self , & tmp_error );
833+ if (tmp_error != NULL ) {
834+ g_propagate_error (err , tmp_error );
835+ return ;
836+ }
837+
838+ GVariant * track_id_variant = g_variant_lookup_value (metadata , "mpris:trackid" , G_VARIANT_TYPE_OBJECT_PATH );
839+ if (track_id_variant == NULL ) {
840+ tmp_error = g_error_new (playerctl_player_error_quark (), 1 , "Could not get track id to set position" );
841+ g_propagate_error (err , tmp_error );
842+ return ;
843+ }
844+
845+ const gchar * track_id = g_variant_get_string (track_id_variant , NULL );
846+
847+ org_mpris_media_player2_player_call_set_position_sync (self -> priv -> proxy , track_id , position , NULL , & tmp_error );
848+ if (tmp_error != NULL ) {
849+ g_propagate_error (err , tmp_error );
850+ return ;
851+ }
852+ }
0 commit comments