Index: trunk/src/lib/sound/ogg_player.cc
===================================================================
--- trunk/src/lib/sound/ogg_player.cc	(revision 7305)
+++ trunk/src/lib/sound/ogg_player.cc	(revision 7306)
@@ -49,4 +49,7 @@
 }
 
+/**
+ * @brief deletes the OggPlayer
+ */
 OggPlayer::~OggPlayer()
 {
@@ -127,4 +130,6 @@
   SoundEngine::checkError("OggPlayer::open()::SetSourceProperties", __LINE__);
 
+  // Set to State Stopped
+  this->state |= OggPlayer::Stopped;
   return true;
 }
@@ -139,4 +144,6 @@
   if (!(this->state & FileOpened))
     return false;
+
+  this->state &= ~(OggPlayer::Stopped | OggPlayer::Paused);
   if (this->musicThread == NULL)
     return ((this->musicThread = SDL_CreateThread(OggPlayer::createAudioThread, (void*)this)) != NULL);
@@ -146,11 +153,29 @@
 
 void OggPlayer::stop()
-{}
+{
+  this->state &= ~(OggPlayer::Playing | OggPlayer::Paused);
+  this->state |= OggPlayer::Stopped;
+
+  this->suspend();
+  this->rewind();
+}
 
 void OggPlayer::pause()
-{}
-
+{
+  this->state &= ~OggPlayer::Playing;
+
+  if (!(this->state & OggPlayer::Stopped))
+    this->state |= OggPlayer::Paused;
+
+  this->suspend();
+}
+
+/**
+ * @brief rewind to the beginning, and play (if already playing)
+ */
 void OggPlayer::rewind()
-{}
+{
+  this->jumpTo(0.0f);
+}
 
 /**
@@ -160,7 +185,19 @@
 void OggPlayer::jumpTo(float timeCode)
 {
-  if (this->state & FileOpened)
+  if (this->state & OggPlayer::FileOpened)
     ov_time_seek(&this->oggStream, timeCode);
 }
+
+/**
+ * @returns the Length of the Music in Seconds
+ */
+float OggPlayer::length()
+{
+  if (this->state & OggPlayer::FileOpened)
+    return ov_time_total(&this->oggStream, -1);
+  else
+    return 0.0f;
+}
+
 
 /**
@@ -183,4 +220,9 @@
 // INTERNAL FUNCTIONS //
 ////////////////////////
+/**
+ * @brief creates a Thread for Playing back the music even if the rest of the Engine is slow
+ * @param oggPlayer the OggPlayer to play back
+ * @returns -1 on error.
+ */
 int OggPlayer::createAudioThread(void* oggPlayer)
 {
@@ -190,7 +232,8 @@
   PRINTF(4)("STARTIG AUDIO THREAD\n");
 
-  ogg->playback();
-
-  while (ogg->state & Playing)
+  if (!ogg->playback())
+    return -1;
+
+  while (ogg->state & OggPlayer::Playing)
   {
     ogg->update();
@@ -200,4 +243,5 @@
 }
 
+
 /**
  * @brief plays back the sound
@@ -206,10 +250,10 @@
 bool OggPlayer::playback()
 {
-  if (!(this->state & FileOpened))
-    return false;
-
-  if(this->isPlaying())
+  if (!(this->state & OggPlayer::FileOpened))
+    return false;
+
+  if(this->state & OggPlayer::Playing)
     return true;
-  this->state |= Playing;
+  this->state |= OggPlayer::Playing;
 
   if(!this->stream(this->buffers[0]) || !this->stream(this->buffers[1]))
@@ -233,5 +277,23 @@
 
 /**
- * updates the stream, this has to be done every few parts of a second, for sound-consistency
+ * @brief waits for the AudioThread to be finished.
+ */
+void OggPlayer::suspend()
+{
+  if (this->musicThread != NULL)
+  {
+    assert (!(this->state & Playing));
+    SDL_WaitThread(this->musicThread, NULL);
+    this->musicThread = NULL;
+  }
+  if (this->state & OggPlayer::SourceAllocated)
+  {
+    alSourceStop(this->source);
+    alSourcei(this->source, AL_BUFFER, 0);
+  }
+}
+
+/**
+ * @brief updates the stream, this has to be done every few parts of a second, for sound-consistency
  * @returns true, if the Sound is playing flawlessly
  */
@@ -267,5 +329,5 @@
 
 /**
- * gets a new Stream from buffer
+ * @brief gets a new Stream from buffer
  * @param buffer the buffer to get the stream from
  * @return true, if everything worked as planed
@@ -311,9 +373,12 @@
   {
     assert(alIsSource(this->source));
-    if (this->state & Playing);
+    if (this->state & OggPlayer::Playing);
     {
-      alSourceStop(source);
+      this->state &= ~OggPlayer::Playing;
+      // Kill the Music Thread.
+      if (this->musicThread != NULL)
+        this->suspend();
+
       SoundEngine::checkError("OggPlayer::release()::alSourceStop", __LINE__);
-      this->state & !Playing;
     }
     empty();
@@ -321,5 +386,5 @@
     SoundEngine::getInstance()->pushALSource(this->source);
     this->source = 0;
-    this->state &= !SourceAllocated;
+    this->state &= ~SourceAllocated;
   }
   if (this->state & BuffersAllocated)
@@ -330,5 +395,5 @@
     this->buffers[0] = 0;
     this->buffers[1] = 0;
-    this->state &= !BuffersAllocated;
+    this->state &= ~BuffersAllocated;
   }
 
@@ -336,14 +401,7 @@
   {
     ov_clear(&oggStream);
-    this->state &= ! FileOpened;
-  }
-
-  // Kill the Music Thread.
-  if (this->musicThread != NULL)
-  {
-    assert (!(this->state & Playing));
-    SDL_WaitThread(this->musicThread, NULL);
-    this->musicThread = NULL;
-  }
+    this->state &= ~FileOpened;
+  }
+
 }
 
