There is a way to PAUSE/RESUME music?

Previous topic - Next topic

Dark Schneider

I think it is an interesting feature, but I don't know if there is currently a way to do this on GLBasic.

Hemlos

You can mute it..

         PLAYMUSIC Music$,1
         MUSICVOLUME Vol#
Bing ChatGpt is pretty smart :O

Slydog

It looks like GLBasic doesn't have a true 'Pause' command.
You can mute it like Hemlos mentioned, but the music will continued to play silently, which might not be a problem.

If it is, you can try talking directly with OpenGL, if that's even how Gernot programmed the sound.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Hatonastick

Actually I think the sound is handled by an SDL library, but I could be wrong.  Being able to pause, or being able to stop and resume at a particular point would be nice. :)
Mat. 5: 14 - 16

Android: Toshiba Thrive Tablet (3.2), Samsung Galaxy Tab 2 (4.1.2).
Netbook: Samsung N150+ Netbook (Win 7 32-bit + Ubuntu 11.10).
Desktop: Intel i5 Desktop with NVIDIA GeForce GTX 460 (Win 8.1 64-bit).

Slydog

Ha, never even thought, OpenGL, hmm, could that be for graphics?!  :-[
OpenAL would have been a better answer!
But SDL does sound familiar now that you mention it.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Millerszone

#5
Here is a pdf of the SDL Library Documentation.
http://www.tr0ll.net/libsdl/docs/sdldoc.pdf

Found this in the Document. Don't know if it for music, but maybe it'll help:
SDL_PauseAudio

Name
SDL_PauseAudio— Pauses and unpauses the audio callback processing

Synopsis
#include "SDL.h"
void SDL_PauseAudio(int pause_on);

Description
This function pauses and unpauses the audio callback processing. It should be called with
pause_on=0 after opening the audio device to start playing sound. This is so you can safely
initialize data for your callback function after opening the audio device. Silence will be written to the
audio device during the pause.

See Also
SDL_GetAudioStatus, SDL_OpenAudio


I believe the above is for Sound, I think you have to use SDL_mixer.h Library to pause Music.

Found this in the SDL_mixer.h file.
/* Pause/Resume a particular channel */
extern DECLSPEC void SDLCALL Mix_Pause(int channel);
extern DECLSPEC void SDLCALL Mix_Resume(int channel);
extern DECLSPEC int SDLCALL Mix_Paused(int channel);

/* Pause/Resume the music stream */
extern DECLSPEC void SDLCALL Mix_PauseMusic(void);
extern DECLSPEC void SDLCALL Mix_ResumeMusic(void);
extern DECLSPEC void SDLCALL Mix_RewindMusic(void);
extern DECLSPEC int SDLCALL Mix_PausedMusic(void);

If you know C language, here is a sample:
Code (glbasic) Select

#include "SDL.h"
#include "SDL_mixer.h"

bool init();
bool load_files();
void clean_up();

Mix_Music   *music  = NULL;
SDL_Surface *screen = NULL;
SDL_Event event;

int main(int argc, char *argv[])
{
    bool quit = false;
   
    if (init() == false)
        return 1;
    if (load_files() == false)
        return 1;
   
    while (quit == false)
    {
        while (SDL_PollEvent(&event))
        {
            if (event.type == SDL_KEYDOWN) {
                if (event.key.keysym.sym == SDLK_SPACE) {
                    if (Mix_PlayingMusic == 0) {
                        if (Mix_PlayMusic(music, -1) == -1)
                            return 1;
                    } else {
                        if (Mix_PausedMusic() == 1)
                            Mix_ResumeMusic();
                        else
                            Mix_PauseMusic();
                    }
                } else if (event.key.keysym.sym == SDLK_ESCAPE) {
                    Mix_HaltMusic();
                }
            } else if (event.type == SDL_QUIT) {
                quit = true;
            }
        }
    }
   
    clean_up();
    return 0;
}

bool init()
{
    if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) == -1)
        return false;
       
    screen = SDL_SetVideoMode(320, 240, 0, 0);
   
    if (screen == NULL)
        return false;
       
    if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1)
        return false;
       
    SDL_WM_SetCaption("Musicplayer", NULL);
   
    return true;
}

bool load_files()
{
    music = Mix_LoadMUS("test.mp3");
   
    if (music == NULL)
        return false;
       
    return true;
}

void clean_up()
{
    Mix_FreeMusic(music);
    Mix_CloseAudio();
    SDL_Quit();
}
Hardware: iMac 27", MacBook Air, PC 3.5Ghz Quad
Developing Tools: GLBasic SDK, Gideros Studio, PureBasic
Developing for: iOS, Android, Windows, OS X, webOS, HTML5

Hatonastick

Quote from: Slydog on 2011-Jan-12
Ha, never even thought, OpenGL, hmm, could that be for graphics?!  :-[
OpenAL would have been a better answer!
But SDL does sound familiar now that you mention it.
Actually I assumed you meant to write OpenAL. :)

I'm not quite sure now which one he uses.  I'm pretty certain SDL_Mixer is used for music, but am not so sure about sound.  Really we need Kitty to chip in and put us all on the right track!
Mat. 5: 14 - 16

Android: Toshiba Thrive Tablet (3.2), Samsung Galaxy Tab 2 (4.1.2).
Netbook: Samsung N150+ Netbook (Win 7 32-bit + Ubuntu 11.10).
Desktop: Intel i5 Desktop with NVIDIA GeForce GTX 460 (Win 8.1 64-bit).

Kitty Hello

unfortunately it's SDL_mixer on Win32, but there's somehting else for Win32 and iPhone. I don't know if I can make it work on all platforms. I'll try.

Dark Schneider

KH is right, using SDL functions only would apply to Win32.

Another good method could be STOPSOUND(channel%), sometimes we have SFX that should be muted instantly, because they have a duration and are made to loop, examples are energy, laser, water, etc. imagine firing a continuous laser beam, and then you stop firing, the sound effect plays until finished, probably about half second after you stopped, the idea is at the moment you release the fire button, send a STOPSOUND().

And, (I am a bit demanding sorry :nw::whip: :blink:) it would be good not to stop the music playing on devices (iPod) when application starts, simply that, there is no need to do any more, then the programmer should put a MUTE (for app sound) button on the main screen and solved. I have tested some apps and this is the way they do, if your are listening music and start an app, they sounds both at the same time, and then you can use the app MUTE feature.
So don't do any more than try that, when GLBasic sound system inits, doesn't stop the current sound/music.

Sorry for the  :bed: