Looping MIDI and Mp3

Just starting out? Need help? Post your questions and find answers here.
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Looping MIDI and Mp3

Post by DriakTravo »

Ok I know you can play Mp3 and MIDI in games using:

Code: Select all

InitMovie()
LoadMovie(0,"sound.mid")
PlayMovie(0,WindowID())
But is there a way to loop the sound so it plays over and over?
Proteus
Enthusiast
Enthusiast
Posts: 113
Joined: Wed Sep 17, 2003 8:04 pm
Location: The Netherlands

Post by Proteus »

if MovieStatus()=0 ; Check if sound is no longer playing
PlayMovie(0,WindowID())
endif
That should do the trick...
P4 2.4GHz, 256 MB, WinXP Pro, onboard video&audio.
The Programmer's Drinking Song:
"99 little bugs in the code,
99 little bugs.
Fix one bug, recompile
100 little bugs in the code."
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

ok, here is the code I have:

Code: Select all

Procedure LoadSpecialSound(Number,SoundFile$)
  InitMovie()
  If LoadMovie(Number,SoundFile$) = 0
    MessageRequester("Error","Failed to load the special sound: "+SoundFile$+". Please make sure the sound file is Mp3 or MIDI")
  EndIf
EndProcedure

Procedure PlaySpecialSound(Number)
  If PlayMovie(Number, WindowID()) = 0
    MessageRequester("Error","Failed to play the special sound: "+Str(Number)+". Please make sure the sound file is Mp3 or MIDI")
  EndIf
EndProcedure

LoadSpecialSound(1,"sound.mid")
PlaySpecialSound(1)
Repeat
  If MovieStatus()=0 ; Check if sound is no longer playing 
    PlayMovie(1,WindowID()) 
  EndIf
ForEver
It does nothing unless I remove the contents of the repeat forever loop.
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

Try....

PlaySpecialSound(1)
Delay(2000)
Repeat

There's some timing issue going on...... The movie doesn't start before you query it..... so it starts again..... then the same thing happens again 8O

I have abandoned the movie commands for now until they are fixed.... NOT quite true, but the principle is there ;)
Paid up PB User !
Proteus
Enthusiast
Enthusiast
Posts: 113
Joined: Wed Sep 17, 2003 8:04 pm
Location: The Netherlands

Post by Proteus »

Code: Select all

Procedure LoadSpecialSound(Number,SoundFile$) 
  InitMovie() 
  If LoadMovie(Number,SoundFile$) = 0 
    MessageRequester("Error","Failed to load the special sound: "+SoundFile$+". Please make sure the sound file is Mp3 or MIDI") 
  EndIf 
EndProcedure 

Procedure PlaySpecialSound(Number) 
  If PlayMovie(Number, WindowID()) = 0 
    MessageRequester("Error","Failed to play the special sound: "+Str(Number)+". Please make sure the sound file is Mp3 or MIDI") 
  EndIf 
EndProcedure 

If OpenWindow(0, 0, 0, 40, 0, #PB_Window_SystemMenu, "...")
  
  LoadSpecialSound(1,"G:\C2notzip\MUSIC\Brainpower - Wat Een Jinx Is.mp3") 
  PlaySpecialSound(1)
  
  Repeat
    If MovieStatus()=0 ; Check if sound is no longer playing 
      PlayMovie(1, WindowID()) 
    EndIf
    Delay(1)
  Until WindowEvent() = #PB_Event_CloseWindow
EndIf
This works.
P4 2.4GHz, 256 MB, WinXP Pro, onboard video&audio.
The Programmer's Drinking Song:
"99 little bugs in the code,
99 little bugs.
Fix one bug, recompile
100 little bugs in the code."
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

Try....

PlaySpecialSound(1)
Delay(2000)
Repeat

There's some timing issue going on...... The movie doesn't start before you query it..... so it starts again..... then the same thing happens again

I have abandoned the movie commands for now until they are fixed.... NOT quite true, but the principle is there
This would work, but if you have the music in a game, it would make the game have a 0.5fps issue.
Code:

Procedure LoadSpecialSound(Number,SoundFile$)
InitMovie()
If LoadMovie(Number,SoundFile$) = 0
MessageRequester("Error","Failed to load the special sound: "+SoundFile$+". Please make sure the sound file is Mp3 or MIDI")
EndIf
EndProcedure

Procedure PlaySpecialSound(Number)
If PlayMovie(Number, WindowID()) = 0
MessageRequester("Error","Failed to play the special sound: "+Str(Number)+". Please make sure the sound file is Mp3 or MIDI")
EndIf
EndProcedure

If OpenWindow(0, 0, 0, 40, 0, #PB_Window_SystemMenu, "...")

LoadSpecialSound(1,"G:\C2notzip\MUSIC\Brainpower - Wat Een Jinx Is.mp3")
PlaySpecialSound(1)

Repeat
If MovieStatus()=0 ; Check if sound is no longer playing
PlayMovie(1, WindowID())
EndIf
Delay(1)
Until WindowEvent() = #PB_Event_CloseWindow
EndIf
This works.
Ok. I have tried this, but it will only play/repeat the sound if I move the window it creates. Nice try though.

If there are any more attempts out there please post them. Your help is greatly apriciated!
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

The 2000 was just a number, it was the delay principle I was trying to make you see...

Never mind :)
Paid up PB User !
Megaborsti
User
User
Posts: 35
Joined: Sat Aug 16, 2003 4:52 pm
Location: Germany

Post by Megaborsti »

If you would know, how long your movie is (... the movielength()-command works only with real movies, not with midi or something), you could start the movie again after that time

Code: Select all

length = [that long is the movie in millisecs]

start = gettickcount_()
playmovie()

Repeat
  IF gettickcount_() > start + length
    stopmovie()
    playmovie()
  Endif
until something

Try it with something like this. I haven´t tried it, but it should work.
I become better!!! :)
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

If you would know, how long your movie is (... the movielength()-command works only with real movies, not with midi or something), you could start the movie again after that time

Code:

length = [that long is the movie in millisecs]

start = gettickcount_()
playmovie()

Repeat
IF gettickcount_() > start + length
stopmovie()
playmovie()
Endif
until something




Try it with something like this. I haven´t tried it, but it should work.
I have a couple of questions: 1-What is that interesting looking gettickcount_() command, what does it return? 2-How can I find out what the length of my movie is?

I wish they would release a patch with more supported streaming compressed auido types. This is starting to get annoying not being able to loop Mp3 or MIDI. :x
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

Try using MP3PLAY.PBI, it's what I use ;)

Uses MCI commands :D
Paid up PB User !
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

Thanks but uh... How do I use it? What are MCI commands? (Im still kinda new to programming.)
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

Look at this thread, and remember you can SEARCH the forum too ;)

viewtopic.php?t=8261&highlight=mp3play+pbi
Paid up PB User !
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

ahhh! Thank you so much It works! I still wish LoadSound() playsound() etc. supported more sound types. It would make it so much easier.
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Post by GPI »

DriakTravo wrote:ahhh! Thank you so much It works! I still wish LoadSound() playsound() etc. supported more sound types. It would make it so much easier.
LoadSound() and PlaySound() load the complete sound into memory (and unpacked!). I would prever a LoadStreamSound() and PlayStreamSound()

GPI
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

Sounds interesting, but, how do you use it? (And I have already tried searching for it). Is it a file you have to include?
Post Reply