Rework state handling to avoid ambiguity between paused and stopped states.
authorIlpo Ruotsalainen <ilpo.ruotsalainen@movial.fi>
Tue, 30 Sep 2008 14:31:23 +0000 (17:31 +0300)
committerIlpo Ruotsalainen <ilpo.ruotsalainen@movial.fi>
Tue, 30 Sep 2008 14:31:23 +0000 (17:31 +0300)
isatis-player/player.c

index 40707a5..acf1ff9 100644 (file)
@@ -20,7 +20,7 @@ typedef struct _PlayerInternal
 
        GstElement *playbin;
 
-       gboolean playing;
+       GstState state;
 } PlayerInternal;
 
 static void prepare_xwindow_id_callback(GstBus *bus, GstMessage *message, PlayerInternal *priv)
@@ -41,7 +41,7 @@ static gboolean update_progress_callback(PlayerInternal *priv)
        gint64 pos, len;
        char tmp[8];
 
-       if (priv->playing)
+       if (priv->state != GST_STATE_NULL)
        {
                if (!gst_element_query_position(priv->playbin, &fmt, &pos))
                        pos = -1;
@@ -52,7 +52,7 @@ static gboolean update_progress_callback(PlayerInternal *priv)
        else
                pos = len = -1;
 
-       if (len != -1 && pos != -1)
+       if (pos != -1 && len > 0)
        {
                double fractional_pos = (double)pos / (double)len;
 
@@ -69,7 +69,7 @@ static gboolean update_progress_callback(PlayerInternal *priv)
        else
                gtk_label_set_text(GTK_LABEL(priv->progressleft), "--:--");
 
-       if (len != -1)
+       if (len > 0)
        {
                int secs = len / 1000000000;
 
@@ -94,7 +94,7 @@ static void stop_playback(PlayerInternal *priv)
 
        gst_element_set_state(priv->playbin, GST_STATE_NULL);
 
-       priv->playing = FALSE;
+       priv->state = GST_STATE_NULL;
        gtk_widget_set_name(GTK_WIDGET(priv->playbutton), "play-button");
 
        update_progress_callback(priv);
@@ -122,13 +122,11 @@ static void state_changed_callback(GstBus *bus, GstMessage *message, PlayerInter
        switch (new)
        {
                case GST_STATE_PLAYING:
-                       priv->playing = TRUE;
                        gtk_widget_set_name(GTK_WIDGET(priv->playbutton), "pause-button");
                        break;
 
                case GST_STATE_NULL:
                case GST_STATE_PAUSED:
-                       priv->playing = FALSE;
                        gtk_widget_set_name(GTK_WIDGET(priv->playbutton), "play-button");
                        break;
 
@@ -141,6 +139,8 @@ static void state_changed_callback(GstBus *bus, GstMessage *message, PlayerInter
                        g_return_if_reached();
        }
 
+       priv->state = new;
+
        update_progress_callback(priv);
 }
 
@@ -191,7 +191,7 @@ static gboolean paint_label_background_callback(GtkWidget *widget, GdkEventExpos
 
 static void playbutton_clicked_callback(GtkButton *button, PlayerInternal *priv)
 {
-       if (priv->playing)
+       if (priv->state == GST_STATE_PLAYING)
                gst_element_set_state(priv->playbin, GST_STATE_PAUSED);
        else
                gst_element_set_state(priv->playbin, GST_STATE_PLAYING);
@@ -319,6 +319,8 @@ int main(int argc, char **argv)
 
        setup_ui(priv);
 
+       priv->state = GST_STATE_NULL;
+
        priv->playbin = gst_element_factory_make("playbin", "playbin");
        g_object_set(G_OBJECT(priv->playbin), "uri", argv[1], NULL);