Page 1 of 1

pause a music module

Posted: Fri Oct 11, 2013 1:36 pm
by Pot Noodle
Hi guys, yes me again :mrgreen:

Just wondering how to pause a music module that's been started with PlayModule(Music)
There is a PauseSound() command but i tried that and it crashed!

I am using mod's for music to keep it Amiga'ish

Thanks

Re: pause a music module

Posted: Fri Oct 11, 2013 6:01 pm
by eesau
Just guessing as I've not used the module/music library, but maybe a combination of GetMusicPosition, StopMusic, and SetMusicPosition?

Re: pause a music module

Posted: Fri Oct 11, 2013 8:59 pm
by Pot Noodle
Ya was thinking this, pain :( maybe it could be an idea for the next release :wink:

Re: pause a music module

Posted: Fri Oct 11, 2013 9:22 pm
by Pot Noodle
Having tried this,

Code: Select all

If KeyboardPushed(#PB_Key_Escape)
		ReleaseMouse(#True)
		PauseSound(#PB_All)
		ModulePos = GetModulePosition(Music)
		If ModulePos > 0
			StopModule(Music)
		EndIf
		If MessageRequester(#Title,"Quit, Are You Sure",#Flags) = 6
			Quit = #True
		Else
			If ModulePos > 0
				SetModulePosition(Music,ModulePos)
				PlayModule(Music)
			EndIf
			ReleaseMouse(#False)
			ResumeSound(#PB_All)
		EndIf
	EndIf
I have tried setting the Position first and then play but No'p
I have tried getModuleRow but not sure about this as there is no SetModuleRow command :?
So it's a no go, Unless some super PB braineak out there :mrgreen:

Re: pause a music module

Posted: Wed Oct 16, 2013 6:21 pm
by TI-994A
Pot Noodle wrote:Just wondering how to pause a music module that's been started with PlayModule(Music)
Hello Pot Noodle. From the following example, it seems that the StopMusic() function actually pauses the music, and any subsequent PlayMusic() call to the corresponding MOD or XM file simply resumes playback from where it was stopped:

Code: Select all

InitNetwork()
InitSound()

Enumeration
  #MainWindow
  #Player1
  #Player2
  #modMusic
  #xmMusic
EndEnumeration

ReceiveHTTPFile("https://www.dropbox.com/s/zqw2pjyytyjq2q5/arabia.mod?dl=1",
                GetTemporaryDirectory() + "arabia.mod")
LoadMusic(#modMusic, GetTemporaryDirectory() + "arabia.mod")
MusicVolume(#modMusic, 60)

ReceiveHTTPFile("https://www.dropbox.com/s/mw1hbw9f1orxkg9/astro.xm?dl=1",
                GetTemporaryDirectory() + "astro.xm")
LoadMusic(#xmMusic, GetTemporaryDirectory() + "astro.xm")
MusicVolume(#xmMusic, 60)

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 300, 100, "PlayMusic", wFlags)
ButtonGadget(#Player1, 30, 30, 100, 30, "Play MOD")
ButtonGadget(#Player2, 170, 30, 100, 30, "Play XM")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      appQuit = 1
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Player1
          If modFlag
            SetGadgetText(#Player1, "Resume")
            StopMusic(#modMusic)
            modFlag = 0
          Else
            SetGadgetText(#Player1, "Pause")
            PlayMusic(#modMusic)
            modFlag = 1
          EndIf
        Case #Player2
          If xmFlag
            SetGadgetText(#Player2, "Resume")
            StopMusic(#xmMusic)
            xmFlag = 0
          Else
            SetGadgetText(#Player2, "Pause")
            PlayMusic(#xmMusic)
            xmFlag = 1
          EndIf
      EndSelect
  EndSelect
Until appQuit = 1
Not entirely sure if this is what you're trying to do though. :)
EDITS wrote:18th February 2019: updated download links

Re: pause a music module

Posted: Tue Oct 22, 2013 2:28 pm
by Pot Noodle
Hi TI-994A,

This is what i am after but even this is not working.
i get an error with LoadMusic(), is this a new command in ver 5.20 ?

Thanks for the help.

rgrds

Re: pause a music module

Posted: Tue Oct 22, 2013 4:23 pm
by TI-994A
Pot Noodle wrote:i get an error with LoadMusic(), is this a new command in ver 5.20 ?
Hi Pot Noodle. You're right; it is new with PureBasic v.5.20. In fact, the entire Module library has been renamed to facilitate the newly introduced module functions. Here's the update from Fred:
Fred wrote:Changed: renamed the whole 'Module' library to 'Music'
Please give this a try; I've replaced the new music functions with their earlier module names, and removed the line continuations, to be more compatible with earlier versions of PureBasic:

Code: Select all

;modified to work with PureBasic versions prior to 5.20

InitNetwork()
InitSound()

Enumeration
  #MainWindow
  #Player1
  #Player2
  #modMusic
  #xmMusic
EndEnumeration

ReceiveHTTPFile("https://www.dropbox.com/s/zqw2pjyytyjq2q5/arabia.mod?dl=1", GetTemporaryDirectory() + "arabia.mod")
LoadModule(#modMusic, GetTemporaryDirectory() + "arabia.mod")

ReceiveHTTPFile("https://www.dropbox.com/s/mw1hbw9f1orxkg9/astro.xm?dl=1", GetTemporaryDirectory() + "astro.xm")
LoadModule(#xmMusic, GetTemporaryDirectory() + "astro.xm")

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 300, 100, "PlayMusic", wFlags)
ButtonGadget(#Player1, 30, 30, 100, 30, "Play MOD")
ButtonGadget(#Player2, 170, 30, 100, 30, "Play XM")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      appQuit = 1
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Player1
          If modFlag
            SetGadgetText(#Player1, "Resume")
            StopModule(#modMusic)
            modFlag = 0
          Else
            SetGadgetText(#Player1, "Pause")
            PlayModule(#modMusic)
            modFlag = 1
          EndIf
        Case #Player2
          If xmFlag
            SetGadgetText(#Player2, "Resume")
            StopModule(#xmMusic)
            xmFlag = 0
          Else
            SetGadgetText(#Player2, "Pause")
            PlayModule(#xmMusic)
            xmFlag = 1
          EndIf
      EndSelect
  EndSelect
Until appQuit = 1
It's been tested with PureBasic v.4.61/x86 and v.5.11/x86, and it works well. :)
EDITS wrote:18th February 2019: updated download links

Re: pause a music module

Posted: Tue Oct 22, 2013 4:47 pm
by Pot Noodle
I must admit that i wondered if stopping the module and playing it would resume from where it left off.
but when i tried it it just started again from the beginning.
But your code works flawlessly, Thanks for taking the time to help mate.

Wish i could repay you for your time :D

Rgrds