Page 1 of 1

Fade out music

Posted: Sun Mar 19, 2017 10:17 pm
by emeck
Hello,

I have a Designer project with an mp3 as background music, loaded in the first page with id 1. I want to fade out the music in the last page, were I have this loop as code in the page:

Code: Select all

For i=64 To 0 Step -1
    SetVolume(1,i)
Next
but when displaying the last page I get the message "Could not find sample 1!" (or "Could not find music 1!" If SetMusicVolume is used). I tried loadin the mp3 as sample or stream and same result.

What Am I missing?

Re: Fade out music

Posted: Sun Mar 19, 2017 11:23 pm
by emeck
Forgot to mention this is with Designer 4 and HW 6.1 on MorphOS 3.9

Re: Fade out music

Posted: Tue Mar 21, 2017 12:13 am
by airsoftsoftwair
You need to assign an ID for the MP3 in the sound dialog, e.g. "MYMUSIC". Then you can access this music by using the %@MYMUSIC wildcard, e.g. like this:

Code: Select all

For i=64 To 0 Step -1
    SetMusicVolume(%@MYMUSIC,i)
    Wait(5)
Next
Note the Wait() call. If you don't use a short delay, the fade will be so fast that it won't be noticeable and the music will just stop right away.

Re: Fade out music

Posted: Tue Mar 21, 2017 2:38 pm
by emeck
airsoftsoftwair wrote:You need to assign an ID for the MP3 in the sound dialog, e.g. "MYMUSIC". Then you can access this music by using the %@MYMUSIC wildcard, e.g. like this:
...
Note the Wait() call. If you don't use a short delay, the fade will be so fast that it won't be noticeable and the music will just stop right away.
Thanks! Working now. Since code executes before the the page or object I had to finish with a last black page with corssfade transition, nice to end videos of a presentation. But music contimues playing until the presentation is closed so just in case I added StopMusic at the end. This is the final code:

Code: Select all

For i  = 64 To 0 Step -1
    SetMusicVolume(%@BMUSIC,i)
    Wait(5)
Next
StopMusic(%@BMUSIC)