/* * call-seq: * jump_to( time ) -> self * * Jump to any time in the Music, in seconds since the beginning. * If the Music was paused, it will still be paused again after the * jump. Does nothing if the Music was stopped. * * **NOTE**: Only works for OGG and MP3 formats! Other formats (e.g. * WAV) will usually raise SDLError. * * time:: the time to jump to, in seconds since the beginning * of the song. (Numeric, required) * * May raise:: SDLError if something goes wrong, or if the music * type does not support jumping. * * **CAUTION**: This method may be unreliable (and could even crash!) * if you jump to a time after the end of the song. Unfortunately, * SDL_Mixer does not provide a way to find the song's length, so * Rubygame cannot warn you if you go off the end. Be careful! */ static VALUE rg_music_jumpto( VALUE self, VALUE vtime ) { RG_Music *music; Data_Get_Struct(self, RG_Music, music); /* Check that the music is current. */ if( _rg_music_current_check(self) ) { /* Only do anything if it's not stopped */ if( !rg_music_stoppedp(self) ) { /* Remember whether it was paused. */ int was_paused = Mix_PausedMusic(); double time = NUM2DBL(vtime); /* in seconds */ if( time < 0 ) { rb_raise(rb_eArgError, "jump_to time cannot be negative (got %d)", time); } int result = Mix_SetMusicPosition( time ); if( result == -1 ) { rb_raise(eSDLError, "Could not jump Music: %s", Mix_GetError()); } /* Pause it again if it was paused before. */ if( was_paused ) { Mix_PauseMusic(); } } } return self; }