@@ -210,6 +210,7 @@ gboolean audio_player_on_bus_message(GstBus *bus, GstMessage *message, struct au
210
210
case GST_MESSAGE_ASYNC_DONE :
211
211
if (!data -> is_seek_completed ) {
212
212
audio_player_on_seek_completed (data );
213
+ data -> is_seek_completed = true;
213
214
}
214
215
break ;
215
216
default :
@@ -288,16 +289,16 @@ void audio_player_on_media_error(struct audio_player *self, GError *error, gchar
288
289
289
290
void audio_player_on_media_state_change (struct audio_player * self , GstObject * src , GstState * old_state , GstState * new_state ) {
290
291
(void ) old_state ;
291
- if (streq ( GST_OBJECT_NAME ( src ), " playbin" )) {
292
+ if (src == GST_OBJECT ( self -> playbin )) {
292
293
LOG_DEBUG ("%s: on_media_state_change(old_state=%d, new_state=%d)\n" , self -> player_id , * old_state , * new_state );
293
294
if (* new_state == GST_STATE_READY ) {
294
- self -> is_initialized = false;
295
-
296
295
// Need to set to pause state, in order to make player functional
297
296
GstStateChangeReturn ret = gst_element_set_state (self -> playbin , GST_STATE_PAUSED );
298
297
if (ret == GST_STATE_CHANGE_FAILURE ) {
299
298
LOG_ERROR ("Unable to set the pipeline to the paused state.\n" );
300
299
}
300
+
301
+ self -> is_initialized = false;
301
302
} else if (* old_state == GST_STATE_PAUSED && * new_state == GST_STATE_PLAYING ) {
302
303
audio_player_on_position_update (self );
303
304
audio_player_on_duration_update (self );
@@ -558,7 +559,10 @@ void audio_player_set_source_url(struct audio_player *self, char *url) {
558
559
if (strlen (self -> url ) != 0 ) {
559
560
g_object_set (self -> playbin , "uri" , self -> url , NULL );
560
561
if (self -> playbin -> current_state != GST_STATE_READY ) {
561
- gst_element_set_state (self -> playbin , GST_STATE_READY );
562
+ if (gst_element_set_state (self -> playbin , GST_STATE_READY ) == GST_STATE_CHANGE_FAILURE ) {
563
+ //This should not happen generally
564
+ LOG_ERROR ("Could not set player into ready state.\n" );
565
+ }
562
566
}
563
567
}
564
568
} else {
@@ -582,3 +586,19 @@ bool audio_player_set_subscription_status(struct audio_player *self, const char
582
586
return false;
583
587
}
584
588
}
589
+
590
+ void audio_player_release (struct audio_player * self ) {
591
+ self -> is_initialized = false;
592
+ self -> is_playing = false;
593
+ if (self -> url != NULL ) {
594
+ free (self -> url );
595
+ self -> url = NULL ;
596
+ }
597
+
598
+ GstState playbinState ;
599
+ gst_element_get_state (self -> playbin , & playbinState , NULL , GST_CLOCK_TIME_NONE );
600
+
601
+ if (playbinState > GST_STATE_NULL ) {
602
+ gst_element_set_state (self -> playbin , GST_STATE_NULL );
603
+ }
604
+ }
0 commit comments