Page 1 of 2

Looping MIDI and Mp3

Posted: Fri Dec 12, 2003 8:18 am
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?

Posted: Fri Dec 12, 2003 1:53 pm
by Proteus
if MovieStatus()=0 ; Check if sound is no longer playing
PlayMovie(0,WindowID())
endif
That should do the trick...

Posted: Fri Dec 12, 2003 9:28 pm
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.

Posted: Fri Dec 12, 2003 10:53 pm
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 ;)

Posted: Sat Dec 13, 2003 12:08 am
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.

Posted: Sat Dec 13, 2003 4:21 am
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!

Posted: Sat Dec 13, 2003 10:25 am
by dontmailme
The 2000 was just a number, it was the delay principle I was trying to make you see...

Never mind :)

Posted: Sat Dec 13, 2003 12:00 pm
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.

Posted: Sat Dec 13, 2003 2:36 pm
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

Posted: Sat Dec 13, 2003 2:50 pm
by dontmailme
Try using MP3PLAY.PBI, it's what I use ;)

Uses MCI commands :D

Posted: Sat Dec 13, 2003 3:53 pm
by DriakTravo
Thanks but uh... How do I use it? What are MCI commands? (Im still kinda new to programming.)

Posted: Sat Dec 13, 2003 7:27 pm
by dontmailme
Look at this thread, and remember you can SEARCH the forum too ;)

viewtopic.php?t=8261&highlight=mp3play+pbi

Posted: Sun Dec 14, 2003 4:58 am
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.

Posted: Sun Dec 14, 2003 11:12 am
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

Posted: Sun Dec 14, 2003 3:00 pm
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?