Merge branch 'master' of https://vcs.maemo.org/git/livewp
[livewp] / applet / src / livewp-scene.c
index 4145bdc..69f71dd 100644 (file)
@@ -166,6 +166,7 @@ bus_call (GstBus *bus, GstMessage *msg, AWallpaperPlugin *desktop_plugin)
      }
        return TRUE;
 }
+
 /*******************************************************************************/
 void
 init_scene_Xsnow(AWallpaperPlugin *desktop_plugin){
@@ -190,6 +191,39 @@ init_scene_Xsnow(AWallpaperPlugin *desktop_plugin){
     }
     g_free(run_string);
 }
+/*******************************************************************************/
+gboolean cb_timeout0(AWallpaperPlugin *desktop_plugin) {
+    GstFormat fmt = GST_FORMAT_TIME;
+    gboolean test;
+    gint64 len;
+    gint len_seconds = 0;
+
+    if (!desktop_plugin || !desktop_plugin->priv->pipeline)
+        return FALSE;
+    if (desktop_plugin->priv->theme_int_parametr1 == 0){
+        if (!gst_element_seek(GST_PIPELINE (desktop_plugin->priv->pipeline), 1.0, GST_FORMAT_TIME,
+                                          GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 
+                                          desktop_plugin->priv->theme_int_parametr1 * GST_SECOND,
+                                          GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
+            fprintf(stderr,"Error in seek:\n");
+        return FALSE;
+    }
+       
+    gst_element_query_position(desktop_plugin->priv->pipeline, &fmt, &len);
+    len_seconds = len / GST_SECOND;
+    if (len <0)
+        return TRUE;
+    if (len_seconds <  desktop_plugin->priv->theme_int_parametr1){
+        if (!gst_element_seek(GST_PIPELINE (desktop_plugin->priv->pipeline), 1.0, GST_FORMAT_TIME,
+                                          GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, 
+                                          desktop_plugin->priv->theme_int_parametr1 * GST_SECOND,
+                                          GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
+            fprintf(stderr,"Error in seek:\n");
+        return TRUE;
+    }else
+        return FALSE;
+} 
+/*******************************************************************************/
 void
 init_scene_Video(AWallpaperPlugin *desktop_plugin)
 {
@@ -199,7 +233,7 @@ init_scene_Video(AWallpaperPlugin *desktop_plugin)
     gchar *file_plus_uri;
 
 
-    fprintf(stderr, "init scene Video \n");
+    /* fprintf(stderr, "init scene Video \n"); */
     desktop_plugin->priv->pipeline = gst_pipeline_new("gst-player");
     bin = gst_element_factory_make ("playbin2", "bin");
     videosink = gst_element_factory_make ("ximagesink", "videosink");
@@ -218,16 +252,13 @@ init_scene_Video(AWallpaperPlugin *desktop_plugin)
 
     if (GST_IS_X_OVERLAY (videosink))
            gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (videosink), GDK_DRAWABLE_XID(desktop_plugin->priv->window->window));
-    if (desktop_plugin->priv->visible)
-        gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
-    
-    fprintf(stderr,"     desktop_plugin->priv->theme_int_parametr1 %i\n",    desktop_plugin->priv->theme_int_parametr1);
-    GstClockTime nach   = (GstClockTime)(desktop_plugin->priv->theme_int_parametr1 * GST_MSECOND);
-    if (!gst_element_seek(desktop_plugin->priv->pipeline, 1.0, GST_FORMAT_TIME,
-                   (GstSeekFlags) (GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT), GST_SEEK_TYPE_SET, 
-                   nach, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE))
-        fprintf(stderr,"Error in seek\n");
 
+    if (desktop_plugin->priv->visible){
+        gst_element_set_state (desktop_plugin->priv->pipeline, GST_STATE_PLAYING);
+        g_timeout_add(100, cb_timeout0, desktop_plugin); 
+    }
+   
+    //gst_element_get_state(deskddtop_plugin->priv->pipeline, NULL, NULL, 100 * GST_MSECOND);
 
 }
 /*******************************************************************************/