pause a music module

Just starting out? Need help? Post your questions and find answers here.
Pot Noodle
Enthusiast
Enthusiast
Posts: 202
Joined: Sat Feb 18, 2012 10:21 pm
Location: Leicestershire

pause a music module

Post 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
P.N.
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Re: pause a music module

Post by eesau »

Just guessing as I've not used the module/music library, but maybe a combination of GetMusicPosition, StopMusic, and SetMusicPosition?
Pot Noodle
Enthusiast
Enthusiast
Posts: 202
Joined: Sat Feb 18, 2012 10:21 pm
Location: Leicestershire

Re: pause a music module

Post by Pot Noodle »

Ya was thinking this, pain :( maybe it could be an idea for the next release :wink:
P.N.
Pot Noodle
Enthusiast
Enthusiast
Posts: 202
Joined: Sat Feb 18, 2012 10:21 pm
Location: Leicestershire

Re: pause a music module

Post 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:
P.N.
User avatar
TI-994A
Addict
Addict
Posts: 2700
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: pause a music module

Post 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
Last edited by TI-994A on Mon Feb 18, 2019 6:34 am, edited 1 time in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Pot Noodle
Enthusiast
Enthusiast
Posts: 202
Joined: Sat Feb 18, 2012 10:21 pm
Location: Leicestershire

Re: pause a music module

Post 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
P.N.
User avatar
TI-994A
Addict
Addict
Posts: 2700
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: pause a music module

Post 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
Last edited by TI-994A on Mon Feb 18, 2019 6:39 am, edited 1 time in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Pot Noodle
Enthusiast
Enthusiast
Posts: 202
Joined: Sat Feb 18, 2012 10:21 pm
Location: Leicestershire

Re: pause a music module

Post 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
P.N.
Post Reply