13 Replies Latest reply on Jul 18, 2007 6:51 AM by tedalde2

    Preloader for sound files

    Opera Rat Level 1
      I don't know where to begin this task. I have a program that plays mp3 files off of a cast that is on a CD-Rom (The entire program must be run from the CD). So before each piece, the CD drive has to spin up and load the next piece which makes for this great delay. How would I go about showing a little animation (not necessarily are real % loaded preloader) while this delay takes place? So while the cd is spinning up and the piece is loading the user will see something happening rather than thinking something is broken. The program plays the pieces in order. So when one is finished it moves on to the next, or the user may choose which piece to listen to (and watch). Of course, when I run the program with files on my hard drive there is no delay, but I don't want the user to install anything on his hard drive.

      Any suggestions?
        • 1. Re: Preloader for sound files
          Level 7
          Does it help if you use the queue() or setPlayList() sound channel commands?
          • 2. Re: Preloader for sound files
            Opera Rat Level 1
            When I told it to queue the next piece as the last page of the current piece is reached, there is a hiccup in the music as the CD spins up. So, I got rid of that.

            I think I'm stuck with the time gap, I just need to know how to put in an animated graphic on the screen as the piece is loading.
            • 3. Re: Preloader for sound files
              Level 7
              You could place a tiny text file on the CD and "touch" it every 5
              seconds or so to stop the CD spinning down.
              -- movie script:
              -- (requires PRegEx xtra, but any file-reading xtra would suit)
              on prepareMovie
              t = timeout().new("no_CD_spin_down", 5000, #mAccessCD, 0)
              end

              on mAccessCD
              tList = re_read(_movie.path & "file.txt")
              end
              • 4. Re: Preloader for sound files
                Opera Rat Level 1
                That could work, but the mp3s total 70 minutes. I guess movies play longer than that.

                Does this script just read some little text file and ignore it over and over? I'll try it. I wonder what will happen when I pause the sound. I think it will work. Thanks.
                • 5. Re: Preloader for sound files
                  Level 7
                  > Does this script just read some little text file and ignore it over and over?

                  Exactly.
                  Accessing a file on the CD regularly should stop it spinning down, but
                  you may still have to deal with seek times. Although this can be
                  somewhat alleviated, it could still be slightly problematic.
                  • 6. Re: Preloader for sound files
                    Opera Rat Level 1
                    I tried it using buddy's baReadIni and the CD light never came on during the piece. I put one script in on preparemovie and the other in on startmovie. The play sound is in the start movie. In every frame there are other scripts running, like when to change the music page (move to the next frame). Do you think that this is were this script should go? If I tell it to do it every frame will it run several of these scripts simultaneously?
                    • 7. Re: Preloader for sound files
                      Level 7
                      I think it needs to happen regularly, but not every frame. I can't tell
                      why yours didn't seem to work - did you use my suggestion of a #timeout
                      object, or did you run it once only?
                      • 8. Re: Preloader for sound files
                        Opera Rat Level 1
                        I used a #timeout. Nothing confuses me more than timeouts. I guess this is something that once it is called keeps doing its thing every so many seconds or so. So once it starts it just keeps doing it's thing until you tell it to forget it. And this scripts thing is to call up on mAccessCD every 30 seconds (which tells it to read some file).

                        Why do I have to use a #name (#mAccessCD) rather than just "mAccessCD"?

                        Do you think it matters that it I'm using ReadIni?

                        If I change the file name to something that is not on my computer "fake.txt" the program doesn't error.
                        • 9. Re: Preloader for sound files
                          Level 7
                          > Why do I have to use a #name (#mAccessCD) rather than just "mAccessCD"?

                          It's a handler name and is required to be provided as a symbol.

                          > Do you think it matters that it I'm using ReadIni?

                          Not as long as the file you are reading works without errors for
                          whatever function you use.
                          The reason I suggested PRegEx is that it will happily read /anything/
                          (including binary executables) without a problem and it's free.

                          > If I change the file name to something that is not on my computer "fake.txt"
                          > the program doesn't error.

                          What do you mean "doesn't error"? Are you experiencing errors? When, and
                          what does the error message report?
                          • 10. Preloader for sound files
                            Opera Rat Level 1
                            I'm not experiencing errors, but I don't think the file is ever accessed. I put tList in the Object inspector and it remains void.
                            Buddy readIni will read any file too. The one you recommended is only for Mac and I need an Xtra that works on both platforms.

                            Here is my .ini file emptyfile.ini
                            [empty]
                            empty=nothing

                            Then in the StartMovie script I have
                            --keeps CD spinning
                            t = timeout().new("CD_Spin_Up", 5000, #mAccessCD, 0)

                            Then in a movie script called CD Access, I have:
                            on mAccessCD
                            tList = baReadini("Empty", "Empty", "not", the moviePath&"emptyfile.ini" )
                            end

                            How can I tell if this file is being read. I tried to see what would happen if I didn't have any ini file and the program ran just the same. I just don't think it's reading this file which is in the same directory as the program file.
                            • 11. Re: Preloader for sound files
                              Level 7
                              > I'm experiencing errors, but I don't think the file is ever accessed.

                              Again, what does the error message say?

                              > The one you recommended is only for Mac
                              > and I need an Xtra that works on both platforms.

                              No, there is a Windows version of the xtra in the archive, but you need
                              to use Stuffit to uncompress/extract it

                              > Here is my .ini file emptyfile.ini
                              > [empty]
                              > empty=nothing
                              >
                              > Then in the StartMovie script I have
                              > --keeps CD spinning
                              > t = timeout().new("CD_Spin_Up", 5000, #mAccessCD, 0)
                              >

                              > on mAccessCD
                              put "accessing CD drive"
                              > tList = baReadini("Empty", "Empty", "not", the moviePath&"emptyfile.ini" )
                              > end
                              >
                              > How can I tell if this file is being read.

                              By examining the result of the 'read' command.
                              I have added a line to the handler above. If you can open a run-time
                              message window (_player.debugPlaybackEnabled = 1) then you can examine
                              output. If you never see the message "accessing CD drive" then the
                              handler isn't being called and your problem lies elsewhere.
                              Are you sure the #startMovie handler is in a #movie script, not a #score
                              or #parent script?
                              • 12. Re: Preloader for sound files
                                Opera Rat Level 1
                                They are movie scripts. I will test this like you said, but in the meantime I think I solved my problem. In order to get rid of the gaps between pieces as they are loaded from an external cast on the CD, I turned the external cast into an internal cast and told it to preload the whole thing (90 Megs). I'm not sure how this works, but it does. The program never has to access the CD again once it loads originally. Of course the program takes longer to load at, but there are no gaps. This will probably be a memory hog. I'm not sure how the whole memory thing works, but my gaps are gone and my splash bmp will give them something to look at while it's loading.
                                • 13. Re: Preloader for sound files
                                  tedalde2 Level 2
                                  Another solution (avoiding preloading):
                                  _movie.go("wait") -- first go to a frame with a "spinning-up/ mp3" message.
                                  updatestage -- need to show frame change mid-code.
                                  sound(1).play(member("yourmp3") -- assumes this is synchronous and causes the spin-up...
                                  _movie.go("playing") -- go to whatever frame you want to show playing mp3.
                                  updatestage

                                  Just a thought, didn't try it. You could also move sprites on/off the stage instead of going to a new frame. Just use updatestage so the stage updates while you're in the code.