Start in PAUSED so clip length is shown since the beginning. Allow orientation change...
authorXavi Artigas <xartigas@fluendo.com>
Mon, 17 Sep 2012 11:48:08 +0000 (13:48 +0200)
committerXavi Artigas <xartigas@fluendo.com>
Mon, 17 Sep 2012 11:48:08 +0000 (13:48 +0200)
gst-sdk/tutorials/android-tutorial-1/jni/tutorial-1.c
gst-sdk/tutorials/android-tutorial-1/src/com/gst_sdk_tutorials/tutorial_1/Tutorial1.java

index 573212c..038699a 100755 (executable)
@@ -154,7 +154,7 @@ static void state_changed_cb (GstBus *bus, GstMessage *msg, CustomData *data) {
   if (GST_MESSAGE_SRC (msg) == GST_OBJECT (data->pipeline)) {
     set_message (gst_element_state_get_name (new_state), data);
     data->state = new_state;
-    if (data->state == GST_STATE_PLAYING && GST_CLOCK_TIME_IS_VALID (data->desired_position)) {
+    if (data->state >= GST_STATE_PAUSED && GST_CLOCK_TIME_IS_VALID (data->desired_position)) {
       execute_seek (data->desired_position, data);
       data->desired_position = GST_CLOCK_TIME_NONE;
     }
@@ -240,6 +240,9 @@ static void *app_function (void *userdata) {
   /* Register a function that GLib will call every second */
   timeout_source_id = g_timeout_add_seconds (1, (GSourceFunc)refresh_ui, data);
 
+  /* Set state to PAUSE, so preroll occurrs and retrieve some information like clip length */
+  gst_element_set_state (data->pipeline, GST_STATE_PAUSED);
+
   /* Create a GLib Main Loop and set it to run */
   GST_DEBUG ("Entering main loop... (CustomData:%p)", data);
   data->main_loop = g_main_loop_new (NULL, FALSE);
index a344b75..e82055a 100755 (executable)
@@ -79,12 +79,14 @@ public class Tutorial1 extends Activity implements SurfaceHolder.Callback, OnSee
 
         nativeInit();
 
-        playing = savedInstanceState==null ? false : savedInstanceState.getBoolean("playing");
-        if (playing) {
+        if (savedInstanceState != null) {
+            playing = savedInstanceState.getBoolean("playing");
             int milliseconds = savedInstanceState.getInt("position");
-            Log.i ("GStreamer", "Restoring to playing state at " + milliseconds + " ms.");
-            nativePlay();
+            Log.i ("GStreamer", "Restoring state, playing:" + playing + " position:" + milliseconds + " ms.");
             nativeSetPosition(milliseconds);
+            if (playing) {
+                nativePlay();
+            }
         }
     }