Index: branches/avi_play/src/lib/graphics/importer/media_container.cc
===================================================================
--- branches/avi_play/src/lib/graphics/importer/media_container.cc	(revision 6382)
+++ branches/avi_play/src/lib/graphics/importer/media_container.cc	(revision 6401)
@@ -40,5 +40,8 @@
 
   if (filename != NULL)
-    this->loadMedia(filename);
+  {
+    if(!this->loadMedia(filename))
+      PRINTF(1)("MediaContainer::loadMedia() failed for %s\n", filename);
+  }
 }
 
@@ -74,5 +77,5 @@
 }
 
-void MediaContainer::loadMedia(const char* filename)
+bool MediaContainer::loadMedia(const char* filename)
 {
   // register all formats and codecs
@@ -81,9 +84,15 @@
   // Open video file
   if (av_open_input_file(&format_context, filename, NULL, 0, NULL) !=0 )
+  {
     PRINTF(1)("Could not open %s\n", filename);
+    return false;
+  }
 
   // Retrieve stream information
   if (av_find_stream_info(format_context) < 0)
+  {
     PRINTF(1)("Could not find stream information in %s\n", filename);
+    return false;
+  }
 
   // Find the first video stream and take it
@@ -91,5 +100,8 @@
   
   if(video_stream == -1)
+  {
     PRINTF(1)("Could not find a video stream in %s\n", filename);
+    return false;
+  }
 
   // Get a pointer to the codec context for the video stream
@@ -101,9 +113,15 @@
   codec = avcodec_find_decoder(codec_context->codec_id);
   if (codec == NULL)
+  {
     PRINTF(1)("Could not find codec\n");
+    return false;
+  }
 
   // Open codec
   if (avcodec_open(codec_context, codec) < 0)
+  {
     PRINTF(1)("Could not open codec\n");
+    return false;
+  }
 
   // Allocate video frame
@@ -123,7 +141,12 @@
   // Calculate fps
   fps = av_q2d(format_context->streams[video_stream]->r_frame_rate);
+  // NOTE: fix this fps problem!!
+  if(fps < 0 || fps > 1000)
+    fps = 30;
 
   // read the frames and save them in a sequence as textures
   this->loadFrames();
+
+  return true;
 }
 
Index: branches/avi_play/src/lib/graphics/importer/media_container.h
===================================================================
--- branches/avi_play/src/lib/graphics/importer/media_container.h	(revision 6382)
+++ branches/avi_play/src/lib/graphics/importer/media_container.h	(revision 6401)
@@ -48,5 +48,5 @@
   ~MediaContainer();
 
-  void loadMedia(const char* filename);
+  bool loadMedia(const char* filename);
   void loadFrames();
 
Index: branches/avi_play/src/lib/graphics/importer/movie_player.cc
===================================================================
--- branches/avi_play/src/lib/graphics/importer/movie_player.cc	(revision 6382)
+++ branches/avi_play/src/lib/graphics/importer/movie_player.cc	(revision 6401)
@@ -34,5 +34,8 @@
 
   if (filename != NULL)
-    this->loadMovie(filename);
+  {
+    if(!this->loadMovie(filename))
+      PRINTF(1)("MoviePlayer::loadMovie() failes for %s\n", filename);
+  }
 }
 
@@ -58,5 +61,5 @@
   av_free(frame);
 
-avcodec_default_free_buffers(codec_context);
+  avcodec_default_free_buffers(codec_context);
 
   // Close the codec
@@ -75,5 +78,5 @@
   timer = 0;
   frame_number = 0;
-  speed = 1;
+  loading = false;
 
   material = new Material;
@@ -88,5 +91,5 @@
 }
 
-void MoviePlayer::loadMovie(const char* filename)
+bool MoviePlayer::loadMovie(const char* filename)
 {
   // register all formats and codecs
@@ -95,9 +98,15 @@
   // Open video file
   if (av_open_input_file(&format_context, filename, NULL, 0, NULL) !=0 )
+  {
     PRINTF(1)("Could not open %s\n", filename);
+    return false;
+  }
 
   // Retrieve stream information
   if (av_find_stream_info(format_context) < 0)
+  {
     PRINTF(1)("Could not find stream information in %s\n", filename);
+    return false;
+  }
 
   // Find the first video stream and take it
@@ -105,5 +114,8 @@
 
   if(video_stream == -1)
+  {
     PRINTF(1)("Could not find a video stream in %s\n", filename);
+    return false;
+  }
 
   // Get a pointer to the codec context for the video stream
@@ -115,9 +127,15 @@
   codec = avcodec_find_decoder(codec_context->codec_id);
   if (codec == NULL)
+  {
     PRINTF(1)("Could not find codec\n");
+    return false;
+  }
 
   // Open codec
   if (avcodec_open(codec_context, codec) < 0)
+  {
     PRINTF(1)("Could not open codec\n");
+    return false;
+  }
 
   // Allocate video frame
@@ -137,4 +155,7 @@
   // Calculate fps
   fps = av_q2d(format_context->streams[video_stream]->r_frame_rate);
+  // NOTE: fix this fps problem!!
+  if(fps < 0 || fps > 1000)
+    fps = 30;
 
   // duration
@@ -155,4 +176,7 @@
               NULL);
   glBindTexture(GL_TEXTURE_2D, 0);
+
+  loading = true;
+  return true;
 }
 
@@ -284,6 +308,13 @@
 }
 
-void MoviePlayer::gotoFrame(int frames)
-{
+bool MoviePlayer::gotoFrame(int frames)
+{
+  if(!loading)
+  {
+    PRINTF(0)("Load first the media file with loadMovie\n");
+    return false;
+  }
+
+  int err;
   // seek doesnt work for the first two frames
   // you will get ugly fragments
@@ -291,6 +322,12 @@
   {
     // go to the begin of the video
-    av_seek_frame(format_context, video_stream, 0, AVSEEK_FLAG_BACKWARD);
-    frame_number = 0;
+    err = av_seek_frame(format_context, video_stream, 0, AVSEEK_FLAG_BACKWARD);
+    if(err < 0)
+    {
+      PRINTF(1)("Could not seek to frame 0\n");
+      return false;
+    }
+
+    this->frame_number = 0;
   }
   else
@@ -298,30 +335,51 @@
     // seeks to the nearest keyframe
     // NOTE: there is only about every 5s a keyframe!
-    av_seek_frame(format_context, video_stream, frames, AVSEEK_FLAG_BACKWARD);
+    err = av_seek_frame(format_context, video_stream, frames, AVSEEK_FLAG_BACKWARD);
+    if(err < 0)
+    {
+      PRINTF(1)("Could not seek to frame %i\n", frames);
+      return false;
+    }
     
     // go from the keyframe to the exact position
     codec_context->hurry_up = 1;
     do {
-      av_read_frame(format_context, &packet);
-      if(packet.pts >= frames-1)
-        break;
-      int frame_finished;
-      avcodec_decode_video(codec_context, frame, &frame_finished, packet.data, packet.size);
-      av_free_packet(&packet);
+      if(av_read_frame(format_context, &packet) < 0)
+      {
+        PRINTF(1)("Could not seek to frame %i\n", frames);
+        return false;
+      }
+
+      if(packet.stream_index == video_stream)
+      {
+        if(packet.pts >= frames-1)
+          break;
+        int frame_finished;
+        avcodec_decode_video(codec_context, frame, &frame_finished, packet.data, packet.size);
+        av_free_packet(&packet);
+      }
     } while(1);
     codec_context->hurry_up = 0;
   
-    frame_number = frames;
-  }
+    this->frame_number = frames;
+  }
+  
+  return true;
 }
 
 void MoviePlayer::start(float start_time)
 {
-  status = PLAY;
-  timer = 0;
-
-  this->gotoFrame(start_time * fps);
-
-   PRINTF(0)("start\n");
+  //start_frame = start_time * fps;
+  start_frame = 0;
+
+  if(this->gotoFrame(start_frame))
+  {
+    status = PLAY;
+    timer = 0;
+  
+    this->gotoFrame(start_frame);
+  
+    PRINTF(0)("start\n");
+  }
 }
 
@@ -356,6 +414,5 @@
   {
     timer += dt;
-    actual_frame = timer * fps * speed;
-
+    actual_frame = timer * fps + start_frame;
     if(actual_frame != frame_number)
     {
@@ -378,13 +435,13 @@
 }
 
-void MoviePlayer::setSpeed(float speed)
-{
-  if(speed > 0)
-    this->speed = speed;
-}
-
-float MoviePlayer::getSpeed()
-{
-  return this->speed;
+void MoviePlayer::setFPS(float fps)
+{
+  if(fps > 0)
+    this->fps = fps;
+}
+
+float MoviePlayer::getFPS()
+{
+  return this->fps;
 }
 
@@ -396,4 +453,10 @@
 void MoviePlayer::printInformation()
 {
+  if(!loading)
+  {
+    PRINTF(0)("Load first the media file with loadMovie\n");
+    return;
+  }
+
   PRINTF(0)("========================\n");
   PRINTF(0)("========================\n");
@@ -410,5 +473,5 @@
   PRINTF(0)("nb_frames: %i\n", format_context->streams[video_stream]->nb_frames);
   PRINTF(0)("r_frame_rate: %i\n", format_context->streams[video_stream]->r_frame_rate.num);
-  PRINTF(0)("fps: %0.2f\n", av_q2d(format_context->streams[video_stream]->r_frame_rate));
+  PRINTF(0)("fps: %0.2f\n", fps);
   PRINTF(0)("========================\n");
   PRINTF(0)("=    AVCodecContext    =\n");
Index: branches/avi_play/src/lib/graphics/importer/movie_player.h
===================================================================
--- branches/avi_play/src/lib/graphics/importer/movie_player.h	(revision 6382)
+++ branches/avi_play/src/lib/graphics/importer/movie_player.h	(revision 6401)
@@ -56,10 +56,11 @@
 
   MP_STATUS status;	
-  float speed;
   float timer;
+  int start_frame;
   int actual_frame;
   int frame_number;
   float fps;
-  int duration;  
+  int duration;
+  bool loading;  
 
 public:
@@ -69,5 +70,5 @@
   ~MoviePlayer();
 
-  void loadMovie(const char* filename);
+  bool loadMovie(const char* filename);
 
 	void start(float start_time);
@@ -79,6 +80,6 @@
 	const void draw();
 
-	void setSpeed(float speed);
-	float getSpeed();
+	void setFPS(float fps);
+	float getFPS();
 	const MP_STATUS getStatus();
   void printInformation();
@@ -89,5 +90,5 @@
   void getNextFrame();
   void skipFrame(int frames);
-  void gotoFrame(int frames);
+  bool gotoFrame(int frames);
 
 };
