Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / the "Music Playing" command seems to not be working

Author
Message
TuscolaMatt
12
Years of Service
User Offline
Joined: 11th Jan 2012
Location:
Posted: 12th Jan 2012 00:04
it always returns a "1"

load music "c:/music/Steve Perry - Go Away.MP3",1
play music 1
while music playing(1)=1
endwhile
load music "c:/music/Steve Perry - Anyway.MP3",1
play music 1
wait key
end

This will play the first song and not the next...why??

From what I've researched, this was buggy a couple years back - it's still not fixed?? Am I approaching this wrong??

I'm trying to write a Jukebox program that will play various lists of songs. I need to know when a song ends to start the next one. Any help would be great.
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 12th Jan 2012 02:39
I couldn't get it to work. A simple work around though - I created an array with the play length of each track in seconds and stored it. This is then loaded back in, then the length multiplied by 1000. Set a variable and read the system timer with "variable=timer()+music length value", then do a simple check every code loop to see if the current timer value has exceeded this value. If so, then play another music track, repeating the process.
For example, my system does this:

This example previously loads the "musicdata" array with the saved file (I have 21 tracks, hence the random seed to choose another track - specific names could be used though). Then a check in the main loop such as:

checks to see if the track end is passed, then calls the function to play another.

The downside is the loading will cause a pause to your games. I wrote a routine that creates a background process to handle it for streaming purposes that eliminates the pause for new tracks but it knocks the framerate by about 10%, so where possible it may be preferable to load all the songs into RAM and then just play different tracks - then no pause.
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 12th Jan 2012 09:56
Quote: "it always returns a "1""

And it always will until you call STOP MUSIC. I had the exact problem once.
I don't know if it's just an example, but you've loaded the same file twice into the same slot. This can cause errors. You need to delete the file occupying a slot to load music into it.

Quote: "I'm trying to write a Jukebox program that will play various lists of songs."

Then you need an internal timer like Santman suggested. You may also look into plugins for extra format support. There may even be some with better music handling.

Also, please place your code in snippets like so:



It makes posts neater and ensures that your code gets formatted properly, making it more legible.

=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 17th Jan 2012 02:27 Edited at: 17th Jan 2012 22:54
I'm not 100% sure about this, but I think the music playing command needs a sync in the loop to work properly.

I have had problems with this before, and I'm sure if you search the forums there are reports of similar problems.

In fact in a spare 30 secs while I wait for the laundry to finish so I can go to bed, I have searched for you...

http://forum.thegamecreators.com/?m=forum_view&t=176255&b=15&msg=2140156#m2140156

This link takes you to an explanation (and work around) by the All knowledgeable and possibly slightly godlike IanM

>Edit<

Just to clarify, not a bug; It's the way it's s'posed to work

nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 17th Jan 2012 22:15
Thats veeery interesting. Always thought SYNC was there for drawing operations... This may alter my entire current game project' structure...

Login to post a reply

Server time is: 2024-11-25 06:11:08
Your offset time is: 2024-11-25 06:11:08