Loading ...
Sorry, an error occurred while loading the content.

Re: [libertybasic] getting a random file

Expand Messages
  • Alyce Watson
    ... Just logging off, so I can t answer in depth. Look in the ebook Multimedia DLL section for the topic on Time Format. You can set the format to be set
    Message 1 of 25 , Jun 2, 2005
    • 0 Attachment
      At 08:16 PM 6/2/2005, you wrote:

      > How can I show the status of the song in minutes and
      >seconds, and how can I tell when the end of the song has been reached?
      >Here's the updated code for the main loop.

      Just logging off, so I can't answer in depth. Look in the ebook Multimedia
      DLL section for the topic on Time Format. You can set the format to be

      "set music time format ms"
      "set music time format TMSF"
      "set music time format bytes"

      Also, if you look at the section on closing files, you'll find this, which
      may come in handy:

      It is possible to close all opened devices with a single "close", when
      "all" is specified instead of a device ID.
      "close all"


      -Alyce


      --
      No virus found in this outgoing message.
      Checked by AVG Anti-Virus.
      Version: 7.0.322 / Virus Database: 267.4.1 - Release Date: 6/2/2005
    • pendl2megabit
      SD, here is your program including the changes to select MP3 and WAV, a continous loop, stopping the music and display of the elapsed song time in MM:SS. Watch
      Message 2 of 25 , Jun 2, 2005
      • 0 Attachment
        SD,
        here is your program including the changes to select MP3 and WAV, a continous
        loop, stopping the music and display of the elapsed song time in MM:SS.
        Watch out for line wraps.

        '---code start
        'No main window.
        nomainwin
        'Set up boolean variables.
        global false, true
        false = 0
        true = 1
        'Set arrays for folder information from three different locations.
        dim musicInfo$(10), wavInfo$(1,1), mp3Info$(1,1)
        dim psaInfo$(10, 10)
        dim idInfo$(10, 10)
        'endless loop variable.
        forEver = false
        'Necessary for displaying folder selection dialog.
        BIF.RETURNONLYFSDIRS = 1
        BIF.USENEWUI = 64
        MAX.PATH = 260
        crlf$=chr$(13)+chr$(10)
        STRUCT BrowseInfo, hWndOwner As Long, pIDLRoot As Long, pszDisplayName As
        Long, _
        lpszTitle$ As ptr, ulFlags As Long, lpfnCallback As Long, lParam As Long,
        iImage As Long

        statictext #main.clock, "", 100, 0, 200, 40
        button #main.Play, "&Play", [PlayMusic], ul, 0, 50
        button #main.stop "&Stop", [StopMusic], ul, 0, 110
        statictext #main.status, "Virtual DJ - Stopped", 0, 200, 350, 30
        menu #main, "&File", "&Print Music Log", [PrintLog], "e&xit", [Exit]
        menu #main, "&Controls", "&Play", [PlayMusic], "&Stop", [StopMusic]
        menu #main, "&Tools", "&Options", [SetOptions]
        menu #main, "&Help", "&Virtual DJ Help", [Help], "&About", [About]
        'checks for settings and creates them if they aren't found.
        'Needs changing to .ini format.
        if FileExists("VDJInfo.dat") = false then
        open "VDJInfo.dat" for output as #info
        notice "Virtual DJ - Setup Wizard" + chr$(13) + "Thank you for using
        VirtualDJ." + _
        chr$(13) + "Please take a moment to complete a few questions so that Virtual
        DJ " + _
        chr$(13) + "will be able to more affectivly meet your needs."
        gosub [SetID]
        gosub [SetMusic]
        gosub [SetPsas]
        gosub [SetStationIDs]
        print #info, "psamode1"
        print #info, "idmode1"
        close #info
        notice "Virtual DJ - Setup Wizard" + chr$(13) + _
        "Thank you for completingthe Virtual DJ setup wizard." + chr$(13) + _
        "You can further customizeVirtual DJ by clicking the Tools menu and" +
        chr$(13) + _
        "selecting options."
        result = mkdir( "music log")
        else
        open "VDJInfo.dat" for input as #info
        input #info, id$
        input #info, mod$
        input #info, id
        input #info, musicFolder$
        input #info, psaFolder$
        input #info, idFolder$
        input #info, psaMode$
        input #info, idMode$
        close #info
        end if
        'set the window to open customized for the station.
        message$ = str$(id) + mod$ + " - " + id$ + " - Virtual DJ"
        open message$ for window as #main
        print #main, "trapclose [Exit]"
        print #main.Play, "!setfocus"
        files musicFolder$, "*.mp3", mp3Info$()
        files musicFolder$, "*.wav", wavInfo$()
        files psaFolder$, psaInfo$()
        files idFolder$, idInfo$()

        totalMP3 = val(mp3Info$(0,0))
        totalWAV = val(wavInfo$(0,0))

        totalMusicFiles = totalMP3 + totalWAV

        redim musicInfo$(totalMusicFiles)

        for count = 1 to totalMP3
        musicInfo$(count) = mp3Info$(count ,0)
        next

        for count = 1 to totalWAV
        musicInfo$(totalMP3 + count) = wavInfo$(count ,0)
        next

        gosub [MainLoop]
        wait

        [MainLoop]
        'loops until program is closed to update clock and play songs while play
        =true.
        do
        dateTime$ = WeekDay$() + ", " + Month$() + " " + _
        mid$(date$("mm/dd/yyyy"),4, 2) + ", " + Now$()
        print #main.clock, dateTime$
        'Sleeps for 50 ms so as not to use 100% of cpu.
        calldll #kernel32,"Sleep",50 as ulong,r as void
        if play = true then
        if nowPlaying = true then
        mPos$=mciSendString$("status music position")
        songPosition = val(mPos$)
        HMS$ = MakeHMS$(songPosition)
        #main.status, "Virtual DJ - "; musicInfo$(randomFile); " - "; HMS$
        if songPosition >= songLength then
        nowPlaying = false
        dummy$=mciSendString$("close music")
        end if
        else
        randomFile = int(rnd(1)*totalMusicFiles)+1
        m$ = chr$(34) + musicFolder$ + "\" + musicInfo$(randomFile) + chr$(34)
        'I commented out this line because it needs the whole path name?
        'm$=GetShortPathName$(m$)
        dummy$=mciSendString$("open "+m$+" alias music")
        dummy$=mciSendString$("set music time format ms")
        mLength$=mciSendString$("status music length")
        songLength = val(mLength$)
        dummy$=mciSendString$("play music")
        nowPlaying = true
        end if
        end if
        scan
        loop until forEver = true
        return

        [PlayMusic]
        play = true
        gosub [MainLoop]
        wait

        [StopMusic]
        play = false
        nowPlaying = false
        dummy$=mciSendString$("close music")
        gosub [MainLoop]
        wait

        [PrintLog]

        wait

        [Help]

        wait

        [About]

        wait

        [Exit]
        close #main
        end


        [SetID]
        do
        prompt "Virtual DJ - Setup Wizard" + chr$(13) + _
        "Please enter your station'sfour letter Identification."; id$
        id$ = upper$(id$)
        if left$(id$, 1) <> "W" and left$(id$, 1) <> "K" then
        notice "User Error" + chr$(13) + _
        "The station identification you entered isinvalid." + _
        chr$(13) + "The first letter must be either K or W."
        id$ = ""
        else
        if len(id$) <> 4 then
        notice "User Error" + chr$(13) + "The " + str$(len(id$)) + _
        " letter identification you entered is invalid." + chr$(13) + _
        "The station identification must be 4 letters in length." + chr$(13) + _
        "Please try again."
        id$ = ""
        end if
        end if
        loop until len(id$) = 4
        gosub [SetModulation]
        if mod$ = "FM" then
        do
        prompt "Virtual DJ - Setup Wizard" + chr$(13) + _
        "Please enter your station's frequency."; id
        if id < 88.0 or id > 108.0 then
        notice "User Error" + chr$(13) + _
        "The station frequency you entered is invalid, please try again."
        end if
        loop while id < 88.0 or id > 108.0
        else
        do
        prompt "Virtual DJ - Setup Wizard" + chr$(13) + _
        "Please enter your station's frequency."; id
        if id < 700 or id > 1600 then
        notice "User Error" + chr$(13) + _
        "The station frequency you entered is invalid, please try again."
        end if
        loop while id < 700 or id > 1600
        end if
        print #info, id$
        print #info, mod$
        print #info, id
        return


        [SetMusic]
        message$ = "Virtual DJ - Setup Wizard" + crlf$ + _
        "Please select the primary music folder."
        gosub [ShowFolders]
        musicFolder$ = sPath$
        return

        [SetPsas]
        message$ = "Virtual DJ - Setup Wizard" + crlf$ + _
        "Please select the folder that contains public service anouncements and/or
        comertials."
        gosub [ShowFolders]
        psaFolder$ = sPath$
        return

        [SetStationIDs]
        message$ = "Virtual DJ - Setup Wizard" + crlf$ + _
        "Please select the folder that contains station identification anouncements."
        gosub [ShowFolders]
        idFolder$ = sPath$
        return

        [SetModulation]
        statictext #mdl.label, "Please choose the station's frequency modulation.", _
        0, 0, 250, 40
        radiobutton #mdl.am, "&Amplitude Modulation", [SetAM], [Unset], 0, 50, 150, 40
        radiobutton #mdl.fm "&Frequency Modulation", [SetFM], [Unset], 0, 100, 150, 40
        button #mdl.ok, "&OK", [Exitmdl], ul, 150, 150
        open "Virtual DJ - Setup Wizard" for dialog_modal as #mdl
        print #mdl.ok, "!disable"
        print #mdl, "trapclose [Exitmdl]"
        wait

        [SetAM]
        mod$ = "AM"
        print #mdl.ok, "!enable"
        wait

        [SetFM]
        mod$ = "FM"
        print #mdl.ok, "!enable"
        wait

        [Unset]
        wait

        [Exitmdl]
        close #mdl
        return

        [ShowFolders]
        BrowseInfo.lpszTitle$.struct = message$
        BrowseInfo.ulFlags.struct = BIF.RETURNONLYFSDIRS or BIF.USENEWUI
        do
        calldll #shell32, "SHBrowseForFolder", BrowseInfo as struct, lpIDList as long
        if lpIDList>0 Then
        sPath$ = space$(MAX.PATH) + chr$(0)
        calldll #shell32, "SHGetPathFromIDList", lpIDList as long, sPath$ as ptr, _
        r as long
        open "ole32" for dll as #ole
        calldll #ole, "CoTaskMemFree", lpIDList as long, r as long
        close #ole
        iNull = InStr(sPath$, chr$(0))
        if iNull Then
        sPath$ = Left$(sPath$, iNull - 1)
        End If
        End If
        loop until sPath$ <> ""
        print #info, sPath$
        return

        'Be sure to include global variables true and false in the main program.
        function FileExists(fileName$)
        dim check$(1, 1)
        files DefaultDir$, fileName$, check$()
        if val(check$(0, 0)) = 1 then
        FileExists = true
        else
        FileExists = false
        end if
        end function

        function LBMod(num1, num2)
        LBMod = num1-int(num1/num2)*num2
        end function

        function WeekDay$()
        month = val(left$(date$("mm/dd/yyyy"), 2))
        day = val(mid$(date$("mm/dd/yyyy"), 4, 2))
        year = val(right$(date$("mm/dd/yyyy"), 4))
        if month > 0 and month <= 2 then
        month = month + 12
        year = year - 1
        end if
        weekDay = LBMod((((month+1)*26)/10 + LBMod(year, 100) + _
        (LBMod(year, 100)) / 4 + year/400 +(year/100)*5 + day-1), 7)
        weekDay = int(weekDay)
        select case weekDay
        case 0
        WeekDay$ = "Sunday"
        case 1
        WeekDay$ = "Monday"
        case 2
        WeekDay$ = "Tuesday"
        case 3
        WeekDay$ = "Wednesday"
        case 4
        WeekDay$ = "Thursday"
        case 5
        WeekDay$ = "Friday"
        case 6
        WeekDay$ = "Saturday"
        end select
        end function

        function Month$()
        month = val(left$(date$("mm/dd/yyyy"), 2))
        select case month
        case 1
        Month$ = "January"
        case 2
        Month$ = "February"
        case 3
        Month$ = "March"
        case 4
        Month$ = "April"
        case 5
        Month$ = "May"
        case 6
        Month$ = "June"
        case 7
        Month$ = "July"
        case 8
        Month$ = "August"
        case 9
        Month$ = "September"
        case 10
        Month$ = "October"
        case 11
        Month$ = "November"
        case 12
        Month$ = "december"
        end select
        end function

        function mciSendString$(s$)
        message$ = s$ + chr$(0)
        buffer$=space$(1024)+chr$(0)
        calldll #winmm,"mciSendStringA",message$ as ptr, buffer$ as ptr, 1024 as
        ulong, _
        0 as ulong, r as ulong
        buffer$=left$(buffer$, instr(buffer$, chr$(0)) - 1)
        if r>0 then
        mciSendString$="error"
        else
        mciSendString$=buffer$
        end if
        end Function

        function Now$()
        hour = val(left$(time$(), 2))
        minute = val(mid$(time$(), 4, 2))
        second = val(right$(time$(), 2))
        if hour > 12 then
        now = hour-12
        else
        now = hour
        end if
        Now$ = str$(now) + ":"
        if minute >= 10 then
        Now$ = Now$ + str$(minute) + ":"
        else
        Now$ = Now$ + "0" + str$(minute) + ":"
        end if
        if second >= 10 then
        Now$ = Now$ + str$(second)
        else
        Now$ = Now$ + "0" + str$(second)
        end if
        if hour >= 12 then
        Now$ = Now$ + "PM"
        else
        Now$ = Now$ + "AM"
        end if
        end function

        Function GetShortPathName$(longPath$)
        longPath$=longPath$ + chr$(0)
        shortPath$ = space$(256)
        lenPath = len(shortPath$)
        calldll #kernel32, "GetShortPathNameA", longPath$ as ptr, shortPath$ as ptr, _
        lenPath as long, r as long
        GetShortPathName$=left$(shortPath$, r)
        end function

        function MakeHMS$(milliseconds)
        minutes = int(milliseconds / (1000 * 60))
        seconds = int((milliseconds - minutes * 60) / 1000)

        MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00"; seconds, 2)
        end function
        '---code end

        ---
        Stefan Pendl


        > -----Ursprüngliche Nachricht-----
        > Von: libertybasic@yahoogroups.com
        >
        > HI,
        > It worked when I played the first song. I forgot that it needed to close
        > the song when it was done with it. I tried updating the status in my
        > statictext that I have at the bottom of the screen, but the time format is
        > kind of wierd. How can I show the status of the song in minutes and
        > seconds, and how can I tell when the end of the song has been reached?
        > Here's the updated code for the main loop.
      • Storm Dragon
        HI, It worked when I played the first song. I forgot that it needed to close the song when it was done with it. I tried updating the status in my statictext
        Message 3 of 25 , Jun 2, 2005
        • 0 Attachment
          HI,
          It worked when I played the first song. I forgot that it needed to close
          the song when it was done with it. I tried updating the status in my
          statictext that I have at the bottom of the screen, but the time format is
          kind of wierd. How can I show the status of the song in minutes and
          seconds, and how can I tell when the end of the song has been reached?
          Here's the updated code for the main loop.

          [MainLoop]
          'loops until program is closed to update clock and play songs while play =
          true.
          do
          dateTime$ = WeekDay$() + ", " + Month$() + " " + mid$(date$("mm/dd/yyyy"),
          4, 2) + ", " + Now$()
          print #main.clock, dateTime$
          'Sleeps for 50 ms so as not to use 100% of cpu.
          calldll #kernel32,"Sleep",50 as ulong,r as void
          if play = true then
          if nowPlaying = true then
          mLength$=mciSendString$("status music length")
          mediaLength = val(mLength$)
          'need if statement here for end of song to set nowPlaying to false and close
          mp3.
          print #main.status, "Virtual DJ - " + songName$ + " - " + str$(mediaLength)
          else
          randomFile = int(rnd(1)*val(musicInfo$(0, 0)))+1
          m$ = chr$(34) + musicInfo$(0, 2) + musicInfo$(0, 3) + musicInfo$(randomFile,
          0) + chr$(34)
          mLength$=mciSendString$("open "+m$+" alias music")
          mLength$=mciSendString$("open "+m$+" alias music")
          mLength$=mciSendString$("play music")
          songName$ = musicInfo$(randomFile, 0)
          nowPlaying = true
          end if
          end if
          scan
          loop until forEver = true
          return


          ----- Original Message -----
          From: "pendl2megabit" <pendl2megabit@...>
          To: <libertybasic@yahoogroups.com>
          Sent: Thursday, June 02, 2005 2:33 PM
          Subject: [libertybasic] getting a random file


          SD,
          you din't tell the media system to play the opened file, so you just have to
          instert the following line directly after opening the media:

          mLength$=mciSendString$("open "+m$+" alias music")
          mLength$=mciSendString$("play music")

          The other problem you have is, that you can not use "*.mp3;*.wav" with the
          files command.
          You will have to get them seperately, this will force you to make
          musicInfo$( a one-dimensional array and add two two-dimensional arrays for
          the
          seperate file types:

          '---code start
          files musicFolder$, "*.mp3", mp3Info$()
          files musicFolder$, "*.wav", wavInfo$()

          totalMP3 = val(mp3Info$(0,0))
          totalWAV = val(wavInfo$(0,0))

          totalMusicFiles = totalMP3 + totalWAV

          redim musicInfo$(totalMusicFiles)

          for count = 1 to totalMP3
          musicInfo$(count) = mp3Info$(count ,0)
          next

          for count = 1 to totalWAV
          musicInfo$(totalMP3 + count) = wavInfo$(count ,0)
          next
          '---code end

          ---
          Stefan Pendl


          > -----Ursprüngliche Nachricht-----
          > Von: libertybasic@yahoogroups.com
          >
          > The code is a little long, but here it is. There are some extra things in
          > it that I haven't finished yet, but it should be able to play music. When
          > you run it, if you set the station as fm, you can have any number
          > between 88
          > and 108. I now get an error when I click play. I can send the error.log
          > file too if that would be helpful.
          > Thanks




          Yahoo! Groups Links
        • Storm Dragon
          Hi, I had to change te format slightly for the time display. It needs to show the time remaining in the songs in minutes and seconds. For example, if a song
          Message 4 of 25 , Jun 4, 2005
          • 0 Attachment
            Hi,
            I had to change te format slightly for the time display. It needs to show
            the time remaining in the songs in minutes and seconds. For example, if a
            song has been playing for 4 seconds, and the song is 4 minutes long, the
            time display should read 03:56. I have gotten the display to work right
            already, but the seconds are a little off. It counts down from 99 seconds
            instead of 59 seconds. Here is the function you sent me:
            function MakeHMS$(milliseconds)
            minutes = int(milliseconds / (1000 * 60))
            seconds = int((milliseconds - minutes * 60) / 1000)
            MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00"; seconds, 2)
            end function

            How can I fix it so that the time is calculated from 59 seconds?
            Thanks
            ----- Original Message -----
            From: "pendl2megabit" <pendl2megabit@...>
            To: <libertybasic@yahoogroups.com>
            Sent: Thursday, June 02, 2005 4:15 PM
            Subject: [libertybasic] getting a random file


            SD,
            here is your program including the changes to select MP3 and WAV, a
            continous
            loop, stopping the music and display of the elapsed song time in MM:SS.
            Watch out for line wraps.

            '---code start
            'No main window.
            nomainwin
            'Set up boolean variables.
            global false, true
            false = 0
            true = 1
            'Set arrays for folder information from three different locations.
            dim musicInfo$(10), wavInfo$(1,1), mp3Info$(1,1)
            dim psaInfo$(10, 10)
            dim idInfo$(10, 10)
            'endless loop variable.
            forEver = false
            'Necessary for displaying folder selection dialog.
            BIF.RETURNONLYFSDIRS = 1
            BIF.USENEWUI = 64
            MAX.PATH = 260
            crlf$=chr$(13)+chr$(10)
            STRUCT BrowseInfo, hWndOwner As Long, pIDLRoot As Long, pszDisplayName As
            Long, _
            lpszTitle$ As ptr, ulFlags As Long, lpfnCallback As Long, lParam As Long,
            iImage As Long

            statictext #main.clock, "", 100, 0, 200, 40
            button #main.Play, "&Play", [PlayMusic], ul, 0, 50
            button #main.stop "&Stop", [StopMusic], ul, 0, 110
            statictext #main.status, "Virtual DJ - Stopped", 0, 200, 350, 30
            menu #main, "&File", "&Print Music Log", [PrintLog], "e&xit", [Exit]
            menu #main, "&Controls", "&Play", [PlayMusic], "&Stop", [StopMusic]
            menu #main, "&Tools", "&Options", [SetOptions]
            menu #main, "&Help", "&Virtual DJ Help", [Help], "&About", [About]
            'checks for settings and creates them if they aren't found.
            'Needs changing to .ini format.
            if FileExists("VDJInfo.dat") = false then
            open "VDJInfo.dat" for output as #info
            notice "Virtual DJ - Setup Wizard" + chr$(13) + "Thank you for using
            VirtualDJ." + _
            chr$(13) + "Please take a moment to complete a few questions so that Virtual
            DJ " + _
            chr$(13) + "will be able to more affectivly meet your needs."
            gosub [SetID]
            gosub [SetMusic]
            gosub [SetPsas]
            gosub [SetStationIDs]
            print #info, "psamode1"
            print #info, "idmode1"
            close #info
            notice "Virtual DJ - Setup Wizard" + chr$(13) + _
            "Thank you for completingthe Virtual DJ setup wizard." + chr$(13) + _
            "You can further customizeVirtual DJ by clicking the Tools menu and" +
            chr$(13) + _
            "selecting options."
            result = mkdir( "music log")
            else
            open "VDJInfo.dat" for input as #info
            input #info, id$
            input #info, mod$
            input #info, id
            input #info, musicFolder$
            input #info, psaFolder$
            input #info, idFolder$
            input #info, psaMode$
            input #info, idMode$
            close #info
            end if
            'set the window to open customized for the station.
            message$ = str$(id) + mod$ + " - " + id$ + " - Virtual DJ"
            open message$ for window as #main
            print #main, "trapclose [Exit]"
            print #main.Play, "!setfocus"
            files musicFolder$, "*.mp3", mp3Info$()
            files musicFolder$, "*.wav", wavInfo$()
            files psaFolder$, psaInfo$()
            files idFolder$, idInfo$()

            totalMP3 = val(mp3Info$(0,0))
            totalWAV = val(wavInfo$(0,0))

            totalMusicFiles = totalMP3 + totalWAV

            redim musicInfo$(totalMusicFiles)

            for count = 1 to totalMP3
            musicInfo$(count) = mp3Info$(count ,0)
            next

            for count = 1 to totalWAV
            musicInfo$(totalMP3 + count) = wavInfo$(count ,0)
            next

            gosub [MainLoop]
            wait

            [MainLoop]
            'loops until program is closed to update clock and play songs while play
            =true.
            do
            dateTime$ = WeekDay$() + ", " + Month$() + " " + _
            mid$(date$("mm/dd/yyyy"),4, 2) + ", " + Now$()
            print #main.clock, dateTime$
            'Sleeps for 50 ms so as not to use 100% of cpu.
            calldll #kernel32,"Sleep",50 as ulong,r as void
            if play = true then
            if nowPlaying = true then
            mPos$=mciSendString$("status music position")
            songPosition = val(mPos$)
            HMS$ = MakeHMS$(songPosition)
            #main.status, "Virtual DJ - "; musicInfo$(randomFile); " - "; HMS$
            if songPosition >= songLength then
            nowPlaying = false
            dummy$=mciSendString$("close music")
            end if
            else
            randomFile = int(rnd(1)*totalMusicFiles)+1
            m$ = chr$(34) + musicFolder$ + "\" + musicInfo$(randomFile) +
            chr$(34)
            'I commented out this line because it needs the whole path name?
            'm$=GetShortPathName$(m$)
            dummy$=mciSendString$("open "+m$+" alias music")
            dummy$=mciSendString$("set music time format ms")
            mLength$=mciSendString$("status music length")
            songLength = val(mLength$)
            dummy$=mciSendString$("play music")
            nowPlaying = true
            end if
            end if
            scan
            loop until forEver = true
            return

            [PlayMusic]
            play = true
            gosub [MainLoop]
            wait

            [StopMusic]
            play = false
            nowPlaying = false
            dummy$=mciSendString$("close music")
            gosub [MainLoop]
            wait

            [PrintLog]

            wait

            [Help]

            wait

            [About]

            wait

            [Exit]
            close #main
            end


            [SetID]
            do
            prompt "Virtual DJ - Setup Wizard" + chr$(13) + _
            "Please enter your station'sfour letter Identification."; id$
            id$ = upper$(id$)
            if left$(id$, 1) <> "W" and left$(id$, 1) <> "K" then
            notice "User Error" + chr$(13) + _
            "The station identification you entered isinvalid." + _
            chr$(13) + "The first letter must be either K or W."
            id$ = ""
            else
            if len(id$) <> 4 then
            notice "User Error" + chr$(13) + "The " + str$(len(id$)) + _
            " letter identification you entered is invalid." + chr$(13) + _
            "The station identification must be 4 letters in length." + chr$(13) + _
            "Please try again."
            id$ = ""
            end if
            end if
            loop until len(id$) = 4
            gosub [SetModulation]
            if mod$ = "FM" then
            do
            prompt "Virtual DJ - Setup Wizard" + chr$(13) + _
            "Please enter your station's frequency."; id
            if id < 88.0 or id > 108.0 then
            notice "User Error" + chr$(13) + _
            "The station frequency you entered is invalid, please try again."
            end if
            loop while id < 88.0 or id > 108.0
            else
            do
            prompt "Virtual DJ - Setup Wizard" + chr$(13) + _
            "Please enter your station's frequency."; id
            if id < 700 or id > 1600 then
            notice "User Error" + chr$(13) + _
            "The station frequency you entered is invalid, please try again."
            end if
            loop while id < 700 or id > 1600
            end if
            print #info, id$
            print #info, mod$
            print #info, id
            return


            [SetMusic]
            message$ = "Virtual DJ - Setup Wizard" + crlf$ + _
            "Please select the primary music folder."
            gosub [ShowFolders]
            musicFolder$ = sPath$
            return

            [SetPsas]
            message$ = "Virtual DJ - Setup Wizard" + crlf$ + _
            "Please select the folder that contains public service anouncements and/or
            comertials."
            gosub [ShowFolders]
            psaFolder$ = sPath$
            return

            [SetStationIDs]
            message$ = "Virtual DJ - Setup Wizard" + crlf$ + _
            "Please select the folder that contains station identification
            anouncements."
            gosub [ShowFolders]
            idFolder$ = sPath$
            return

            [SetModulation]
            statictext #mdl.label, "Please choose the station's frequency modulation.",
            _
            0, 0, 250, 40
            radiobutton #mdl.am, "&Amplitude Modulation", [SetAM], [Unset], 0, 50, 150,
            40
            radiobutton #mdl.fm "&Frequency Modulation", [SetFM], [Unset], 0, 100, 150,
            40
            button #mdl.ok, "&OK", [Exitmdl], ul, 150, 150
            open "Virtual DJ - Setup Wizard" for dialog_modal as #mdl
            print #mdl.ok, "!disable"
            print #mdl, "trapclose [Exitmdl]"
            wait

            [SetAM]
            mod$ = "AM"
            print #mdl.ok, "!enable"
            wait

            [SetFM]
            mod$ = "FM"
            print #mdl.ok, "!enable"
            wait

            [Unset]
            wait

            [Exitmdl]
            close #mdl
            return

            [ShowFolders]
            BrowseInfo.lpszTitle$.struct = message$
            BrowseInfo.ulFlags.struct = BIF.RETURNONLYFSDIRS or BIF.USENEWUI
            do
            calldll #shell32, "SHBrowseForFolder", BrowseInfo as struct, lpIDList as
            long
            if lpIDList>0 Then
            sPath$ = space$(MAX.PATH) + chr$(0)
            calldll #shell32, "SHGetPathFromIDList", lpIDList as long, sPath$ as ptr, _
            r as long
            open "ole32" for dll as #ole
            calldll #ole, "CoTaskMemFree", lpIDList as long, r as long
            close #ole
            iNull = InStr(sPath$, chr$(0))
            if iNull Then
            sPath$ = Left$(sPath$, iNull - 1)
            End If
            End If
            loop until sPath$ <> ""
            print #info, sPath$
            return

            'Be sure to include global variables true and false in the main program.
            function FileExists(fileName$)
            dim check$(1, 1)
            files DefaultDir$, fileName$, check$()
            if val(check$(0, 0)) = 1 then
            FileExists = true
            else
            FileExists = false
            end if
            end function

            function LBMod(num1, num2)
            LBMod = num1-int(num1/num2)*num2
            end function

            function WeekDay$()
            month = val(left$(date$("mm/dd/yyyy"), 2))
            day = val(mid$(date$("mm/dd/yyyy"), 4, 2))
            year = val(right$(date$("mm/dd/yyyy"), 4))
            if month > 0 and month <= 2 then
            month = month + 12
            year = year - 1
            end if
            weekDay = LBMod((((month+1)*26)/10 + LBMod(year, 100) + _
            (LBMod(year, 100)) / 4 + year/400 +(year/100)*5 + day-1), 7)
            weekDay = int(weekDay)
            select case weekDay
            case 0
            WeekDay$ = "Sunday"
            case 1
            WeekDay$ = "Monday"
            case 2
            WeekDay$ = "Tuesday"
            case 3
            WeekDay$ = "Wednesday"
            case 4
            WeekDay$ = "Thursday"
            case 5
            WeekDay$ = "Friday"
            case 6
            WeekDay$ = "Saturday"
            end select
            end function

            function Month$()
            month = val(left$(date$("mm/dd/yyyy"), 2))
            select case month
            case 1
            Month$ = "January"
            case 2
            Month$ = "February"
            case 3
            Month$ = "March"
            case 4
            Month$ = "April"
            case 5
            Month$ = "May"
            case 6
            Month$ = "June"
            case 7
            Month$ = "July"
            case 8
            Month$ = "August"
            case 9
            Month$ = "September"
            case 10
            Month$ = "October"
            case 11
            Month$ = "November"
            case 12
            Month$ = "december"
            end select
            end function

            function mciSendString$(s$)
            message$ = s$ + chr$(0)
            buffer$=space$(1024)+chr$(0)
            calldll #winmm,"mciSendStringA",message$ as ptr, buffer$ as ptr, 1024 as
            ulong, _
            0 as ulong, r as ulong
            buffer$=left$(buffer$, instr(buffer$, chr$(0)) - 1)
            if r>0 then
            mciSendString$="error"
            else
            mciSendString$=buffer$
            end if
            end Function

            function Now$()
            hour = val(left$(time$(), 2))
            minute = val(mid$(time$(), 4, 2))
            second = val(right$(time$(), 2))
            if hour > 12 then
            now = hour-12
            else
            now = hour
            end if
            Now$ = str$(now) + ":"
            if minute >= 10 then
            Now$ = Now$ + str$(minute) + ":"
            else
            Now$ = Now$ + "0" + str$(minute) + ":"
            end if
            if second >= 10 then
            Now$ = Now$ + str$(second)
            else
            Now$ = Now$ + "0" + str$(second)
            end if
            if hour >= 12 then
            Now$ = Now$ + "PM"
            else
            Now$ = Now$ + "AM"
            end if
            end function

            Function GetShortPathName$(longPath$)
            longPath$=longPath$ + chr$(0)
            shortPath$ = space$(256)
            lenPath = len(shortPath$)
            calldll #kernel32, "GetShortPathNameA", longPath$ as ptr, shortPath$ as ptr,
            _
            lenPath as long, r as long
            GetShortPathName$=left$(shortPath$, r)
            end function

            function MakeHMS$(milliseconds)
            minutes = int(milliseconds / (1000 * 60))
            seconds = int((milliseconds - minutes * 60) / 1000)

            MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00"; seconds, 2)
            end function
            '---code end

            ---
            Stefan Pendl


            > -----Ursprüngliche Nachricht-----
            > Von: libertybasic@yahoogroups.com
            >
            > HI,
            > It worked when I played the first song. I forgot that it needed to close
            > the song when it was done with it. I tried updating the status in my
            > statictext that I have at the bottom of the screen, but the time format is
            > kind of wierd. How can I show the status of the song in minutes and
            > seconds, and how can I tell when the end of the song has been reached?
            > Here's the updated code for the main loop.




            Yahoo! Groups Links
          • pendl2megabit
            SD, I don t see the problem you have ??? To display the time remaining, do you use: HMS$ = MakeHMS$(songLength - songPosition) The function works correctly,
            Message 5 of 25 , Jun 6, 2005
            • 0 Attachment
              SD,
              I don't see the problem you have ???
              To display the time remaining, do you use:
              HMS$ = MakeHMS$(songLength - songPosition)

              The function works correctly, the base is 60 not 100.
              I don't know what could be wrong ???

              ---
              Stefan Pendl

              -----Ursprüngliche Nachricht-----
              Von: libertybasic@yahoogroups.com

              Hi,
              I had to change te format slightly for the time display. It needs to show
              the time remaining in the songs in minutes and seconds. For example, if a
              song has been playing for 4 seconds, and the song is 4 minutes long, the
              time display should read 03:56. I have gotten the display to work right
              already, but the seconds are a little off. It counts down from 99 seconds
              instead of 59 seconds. Here is the function you sent me:
              function MakeHMS$(milliseconds)
              minutes = int(milliseconds / (1000 * 60))
              seconds = int((milliseconds - minutes * 60) / 1000)
              MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00"; seconds, 2)
              end function

              How can I fix it so that the time is calculated from 59 seconds?
              Thanks
            • pendl2megabit
              SD, from the portions of code you posted, I am not able to find the problem source. I have a working demo here, but I need to see your whole code to be able to
              Message 6 of 25 , Jun 7, 2005
              • 0 Attachment
                SD,
                from the portions of code you posted, I am not able to find the problem
                source.
                I have a working demo here, but I need to see your whole code to be able to
                spot the bug.

                ---
                Stefan Pendl


                -----Ursprüngliche Nachricht-----
                Von: libertybasic@yahoogroups.com

                Hi,
                I did basically what you have below, but I assigned it to a new variable to
                cut down on what I had to type in the display line.
                I have:
                mPosition = mediaLength-musicPosition
                print #main.status, GetSongTitle$(songName$) + chr$(13) +
                MakeHMS$(mPosition)
                When setting the format for the length, I did it in ms format. Here's the
                lines of code:
                mLength$ = mciSendString$("set music time format ms")
                mLength$=mciSendString$("status music length")
                Here's the function you sent me for quick reference:
                function MakeHMS$(milliseconds)
                minutes = int(milliseconds / (1000 * 60))
                seconds = int((milliseconds - minutes * 60) / 1000)
                MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00"; seconds, 2)
                end function

                Just to be sure, I played a song, and the starting time displayed was 05:52.
                When it reached 5:00, the very next time displayed was 05:99.
                Thanks
              • Storm Dragon
                Hi, I did basically what you have below, but I assigned it to a new variable to cut down on what I had to type in the display line. I have: mPosition =
                Message 7 of 25 , Jun 7, 2005
                • 0 Attachment
                  Hi,
                  I did basically what you have below, but I assigned it to a new variable to
                  cut down on what I had to type in the display line.
                  I have:
                  mPosition = mediaLength-musicPosition
                  print #main.status, GetSongTitle$(songName$) + chr$(13) +
                  MakeHMS$(mPosition)
                  When setting the format for the length, I did it in ms format. Here's the
                  lines of code:
                  mLength$ = mciSendString$("set music time format ms")
                  mLength$=mciSendString$("status music length")
                  Here's the function you sent me for quick reference:
                  function MakeHMS$(milliseconds)
                  minutes = int(milliseconds / (1000 * 60))
                  seconds = int((milliseconds - minutes * 60) / 1000)
                  MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00"; seconds, 2)
                  end function

                  Just to be sure, I played a song, and the starting time displayed was 05:52.
                  When it reached 5:00, the very next time displayed was 05:99.
                  Thanks


                  ----- Original Message -----
                  From: "pendl2megabit" <pendl2megabit@...>
                  To: <libertybasic@yahoogroups.com>
                  Sent: Monday, June 06, 2005 8:14 AM
                  Subject: [libertybasic] getting a random file


                  SD,
                  I don't see the problem you have ???
                  To display the time remaining, do you use:
                  HMS$ = MakeHMS$(songLength - songPosition)

                  The function works correctly, the base is 60 not 100.
                  I don't know what could be wrong ???

                  ---
                  Stefan Pendl

                  -----Ursprüngliche Nachricht-----
                  Von: libertybasic@yahoogroups.com

                  Hi,
                  I had to change te format slightly for the time display. It needs to show
                  the time remaining in the songs in minutes and seconds. For example, if a
                  song has been playing for 4 seconds, and the song is 4 minutes long, the
                  time display should read 03:56. I have gotten the display to work right
                  already, but the seconds are a little off. It counts down from 99 seconds
                  instead of 59 seconds. Here is the function you sent me:
                  function MakeHMS$(milliseconds)
                  minutes = int(milliseconds / (1000 * 60))
                  seconds = int((milliseconds - minutes * 60) / 1000)
                  MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00"; seconds, 2)
                  end function

                  How can I fix it so that the time is calculated from 59 seconds?
                  Thanks




                  Yahoo! Groups Links
                • Storm Dragon
                  Hi, My code has gotten quite large, so to save posting the whole thing, I made a smaller version. I checked, and it still has the same problem. I tested it
                  Message 8 of 25 , Jun 8, 2005
                  • 0 Attachment
                    Hi,
                    My code has gotten quite large, so to save posting the whole thing, I made a
                    smaller version. I checked, and it still has the same problem. I tested it
                    on a song that lasts about 5 minutes and 50 seconds. When the display
                    changed from 05:00 it went to 04:99. Here's the code:
                    nomainwin
                    button #main.play, "&Play", [playmusic], ul, 0, 0
                    button #main.exit, "E&xit", [exit], ul, 0, 50
                    statictext #main.status, "", 0, 200, 500, 60
                    open "Mini mp3 Player" for window as #main
                    print #main, "trapclose [exit]"
                    wait

                    [playmusic]
                    filedialog "Open an mp3 file", "*.mp3", songName$
                    if songName$ <> "" then
                    m$ = chr$(34) + songName$ + chr$(34)
                    mLength$=mciSendString$("open "+m$+" alias music")
                    mLength$=mciSendString$("play music")
                    mLength$ = mciSendString$("set music time format ms")
                    mLength$=mciSendString$("status music length")
                    mediaLength = val(mLength$)
                    playing = 1
                    gosub [timeloop]
                    end if
                    wait

                    [timeloop]
                    do
                    mLength$ = mciSendString$("status music position")
                    musicPosition = val(mLength$)
                    if musicPosition >= mediaLength then
                    mLength$=mciSendString$("close music")
                    playing = 0
                    else
                    mPosition = mediaLength-musicPosition
                    print #main.status, GetSongTitle$(songName$) + chr$(13) +
                    MakeHMS$(mPosition)
                    end if
                    'Sleeps for 100 ms so as not to use 100% of cpu.
                    calldll #kernel32, "Sleep", 100 as ulong,r as void
                    scan
                    loop until playing = 0
                    return

                    [exit]
                    if playing = 1 then
                    mLength$=mciSendString$("close music")
                    end if
                    close #main
                    end

                    function mciSendString$(s$)
                    buffer$=space$(1024)+chr$(0)
                    calldll #winmm,"mciSendStringA",s$ as ptr, buffer$ as ptr, 1028 as long, 0
                    as long, r as long
                    buffer$=left$(buffer$, instr(buffer$, chr$(0)) - 1)
                    if r>0 then
                    mciSendString$="error"
                    else
                    mciSendString$=buffer$
                    end if
                    end Function

                    function MakeHMS$(milliseconds)
                    minutes = int(milliseconds / (1000 * 60))
                    seconds = int((milliseconds - minutes * 60) / 1000)
                    MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00"; seconds, 2)
                    end function

                    function GetSongTitle$(song$)
                    songEnd$ = right$(song$, 5)
                    songEnd = instr(song$, songEnd$)
                    GetSongTitle$ = left$(song$, songEnd)
                    end function

                    ----- Original Message -----
                    From: "pendl2megabit" <pendl2megabit@...>
                    To: <libertybasic@yahoogroups.com>
                    Sent: Tuesday, June 07, 2005 3:32 PM
                    Subject: AW: [libertybasic] getting a random file


                    SD,
                    from the portions of code you posted, I am not able to find the problem
                    source.
                    I have a working demo here, but I need to see your whole code to be able to
                    spot the bug.

                    ---
                    Stefan Pendl


                    -----Ursprüngliche Nachricht-----
                    Von: libertybasic@yahoogroups.com

                    Hi,
                    I did basically what you have below, but I assigned it to a new variable to
                    cut down on what I had to type in the display line.
                    I have:
                    mPosition = mediaLength-musicPosition
                    print #main.status, GetSongTitle$(songName$) + chr$(13) +
                    MakeHMS$(mPosition)
                    When setting the format for the length, I did it in ms format. Here's the
                    lines of code:
                    mLength$ = mciSendString$("set music time format ms")
                    mLength$=mciSendString$("status music length")
                    Here's the function you sent me for quick reference:
                    function MakeHMS$(milliseconds)
                    minutes = int(milliseconds / (1000 * 60))
                    seconds = int((milliseconds - minutes * 60) / 1000)
                    MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00"; seconds, 2)
                    end function

                    Just to be sure, I played a song, and the starting time displayed was 05:52.
                    When it reached 5:00, the very next time displayed was 05:99.
                    Thanks




                    Yahoo! Groups Links
                  • Mike
                    ... thing, I made a ... tested it ... display ... seconds, 2) ... was 05:52. ... Storm Dragon Maybe the function has an error? Try seconds = int((milliseconds
                    Message 9 of 25 , Jun 8, 2005
                    • 0 Attachment
                      --- In libertybasic@yahoogroups.com, "Storm Dragon"
                      <stormdragon2976@c...> wrote:
                      > Hi,
                      > My code has gotten quite large, so to save posting the whole
                      thing, I made a
                      > smaller version. I checked, and it still has the same problem. I
                      tested it
                      > on a song that lasts about 5 minutes and 50 seconds. When the
                      display
                      > changed from 05:00 it went to 04:99.

                      > Here's the function you sent me for quick reference:
                      > function MakeHMS$(milliseconds)
                      > minutes = int(milliseconds / (1000 * 60))
                      > seconds = int((milliseconds - minutes * 60) / 1000)
                      > MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00";
                      seconds, 2)
                      > end function
                      >
                      > Just to be sure, I played a song, and the starting time displayed
                      was 05:52.
                      > When it reached 5:00, the very next time displayed was 05:99.
                      > Thanks
                      >

                      Storm Dragon

                      Maybe the function has an error?
                      Try seconds = int((milliseconds - minutes * 60000) / 1000)

                      Mike.
                    • rodbirdathome
                      milliseconds=time$( ms ) print MakeHMSM$(milliseconds) wait function MakeHMSM$(ms) hours = int(ms / 3600000) 3,600,000 ms in an hour minutes =
                      Message 10 of 25 , Jun 8, 2005
                      • 0 Attachment
                        milliseconds=time$("ms")
                        print MakeHMSM$(milliseconds)
                        wait

                        function MakeHMSM$(ms)
                        hours = int(ms / 3600000)
                        ' 3,600,000 ms in an hour
                        minutes = int((ms-(hours*3600000)) / 60000)
                        ' 60,000 ms in a minute
                        seconds = int((ms-((hours*3600000)+(minutes*60000))) / 1000)
                        '1000 ms in a second
                        msec = ms - ((hours*3600000) + (minutes*60000))
                        MakeHMSM$ =
                        right$("00"+str$(hours),2);":";right$("00"+str$(minutes),2);":";right$(
                        "000000"+str$(msec),5)
                        end function
                      • pendl2megabit
                        SD, sorry, but it was my fault, I never tried a song longer than one minute :-( The correct function is: ---code start function MakeHMS$(milliseconds) minutes
                        Message 11 of 25 , Jun 8, 2005
                        • 0 Attachment
                          SD,
                          sorry, but it was my fault, I never tried a song longer than one minute :-(
                          The correct function is:

                          '---code start
                          function MakeHMS$(milliseconds)
                          minutes = int(milliseconds / (1000 * 60))
                          seconds = int((milliseconds - minutes * 1000 * 60) / 1000)
                          MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00"; seconds, 2)
                          end function
                          '---code end

                          The problem was calculating the seconds >:-(

                          I tested this with Carls interview at the Techwatch Radio and it works
                          correctly now.

                          ---
                          Stefan Pendl


                          -----Ursprüngliche Nachricht-----
                          Von: libertybasic@yahoogroups.com

                          Hi,
                          My code has gotten quite large, so to save posting the whole thing, I made a
                          smaller version. I checked, and it still has the same problem. I tested it
                          on a song that lasts about 5 minutes and 50 seconds. When the display
                          changed from 05:00 it went to 04:99. Here's the code:
                          nomainwin
                          button #main.play, "&Play", [playmusic], ul, 0, 0
                          button #main.exit, "E&xit", [exit], ul, 0, 50
                          statictext #main.status, "", 0, 200, 500, 60
                          open "Mini mp3 Player" for window as #main
                          print #main, "trapclose [exit]"
                          wait

                          [playmusic]
                          filedialog "Open an mp3 file", "*.mp3", songName$
                          if songName$ <> "" then
                          m$ = chr$(34) + songName$ + chr$(34)
                          mLength$=mciSendString$("open "+m$+" alias music")
                          mLength$=mciSendString$("play music")
                          mLength$ = mciSendString$("set music time format ms")
                          mLength$=mciSendString$("status music length")
                          mediaLength = val(mLength$)
                          playing = 1
                          gosub [timeloop]
                          end if
                          wait

                          [timeloop]
                          do
                          mLength$ = mciSendString$("status music position")
                          musicPosition = val(mLength$)
                          if musicPosition >= mediaLength then
                          mLength$=mciSendString$("close music")
                          playing = 0
                          else
                          mPosition = mediaLength-musicPosition
                          print #main.status, GetSongTitle$(songName$) + chr$(13) +
                          MakeHMS$(mPosition)
                          end if
                          'Sleeps for 100 ms so as not to use 100% of cpu.
                          calldll #kernel32, "Sleep", 100 as ulong,r as void
                          scan
                          loop until playing = 0
                          return

                          [exit]
                          if playing = 1 then
                          mLength$=mciSendString$("close music")
                          end if
                          close #main
                          end

                          function mciSendString$(s$)
                          buffer$=space$(1024)+chr$(0)
                          calldll #winmm,"mciSendStringA",s$ as ptr, buffer$ as ptr, 1028 as long, 0
                          as long, r as long
                          buffer$=left$(buffer$, instr(buffer$, chr$(0)) - 1)
                          if r>0 then
                          mciSendString$="error"
                          else
                          mciSendString$=buffer$
                          end if
                          end Function

                          function MakeHMS$(milliseconds)
                          minutes = int(milliseconds / (1000 * 60))
                          seconds = int((milliseconds - minutes * 60) / 1000)
                          MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00"; seconds, 2)
                          end function

                          function GetSongTitle$(song$)
                          songEnd$ = right$(song$, 5)
                          songEnd = instr(song$, songEnd$)
                          GetSongTitle$ = left$(song$, songEnd)
                          end function
                        • Storm Dragon
                          Thanks for the help once again. If I ever get this thing finished, you and a couple of others will most definitely be in the credits. ... From:
                          Message 12 of 25 , Jun 8, 2005
                          • 0 Attachment
                            Thanks for the help once again. If I ever get this thing finished, you and
                            a couple of others will most definitely be in the credits.
                            ----- Original Message -----
                            From: "pendl2megabit" <pendl2megabit@...>
                            To: <libertybasic@yahoogroups.com>
                            Sent: Wednesday, June 08, 2005 3:27 PM
                            Subject: AW: [libertybasic] getting a random file


                            SD,
                            sorry, but it was my fault, I never tried a song longer than one minute :-(
                            The correct function is:

                            '---code start
                            function MakeHMS$(milliseconds)
                            minutes = int(milliseconds / (1000 * 60))
                            seconds = int((milliseconds - minutes * 1000 * 60) / 1000)
                            MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00"; seconds, 2)
                            end function
                            '---code end

                            The problem was calculating the seconds >:-(

                            I tested this with Carls interview at the Techwatch Radio and it works
                            correctly now.

                            ---
                            Stefan Pendl


                            -----Ursprüngliche Nachricht-----
                            Von: libertybasic@yahoogroups.com

                            Hi,
                            My code has gotten quite large, so to save posting the whole thing, I made a
                            smaller version. I checked, and it still has the same problem. I tested it
                            on a song that lasts about 5 minutes and 50 seconds. When the display
                            changed from 05:00 it went to 04:99. Here's the code:
                            nomainwin
                            button #main.play, "&Play", [playmusic], ul, 0, 0
                            button #main.exit, "E&xit", [exit], ul, 0, 50
                            statictext #main.status, "", 0, 200, 500, 60
                            open "Mini mp3 Player" for window as #main
                            print #main, "trapclose [exit]"
                            wait

                            [playmusic]
                            filedialog "Open an mp3 file", "*.mp3", songName$
                            if songName$ <> "" then
                            m$ = chr$(34) + songName$ + chr$(34)
                            mLength$=mciSendString$("open "+m$+" alias music")
                            mLength$=mciSendString$("play music")
                            mLength$ = mciSendString$("set music time format ms")
                            mLength$=mciSendString$("status music length")
                            mediaLength = val(mLength$)
                            playing = 1
                            gosub [timeloop]
                            end if
                            wait

                            [timeloop]
                            do
                            mLength$ = mciSendString$("status music position")
                            musicPosition = val(mLength$)
                            if musicPosition >= mediaLength then
                            mLength$=mciSendString$("close music")
                            playing = 0
                            else
                            mPosition = mediaLength-musicPosition
                            print #main.status, GetSongTitle$(songName$) + chr$(13) +
                            MakeHMS$(mPosition)
                            end if
                            'Sleeps for 100 ms so as not to use 100% of cpu.
                            calldll #kernel32, "Sleep", 100 as ulong,r as void
                            scan
                            loop until playing = 0
                            return

                            [exit]
                            if playing = 1 then
                            mLength$=mciSendString$("close music")
                            end if
                            close #main
                            end

                            function mciSendString$(s$)
                            buffer$=space$(1024)+chr$(0)
                            calldll #winmm,"mciSendStringA",s$ as ptr, buffer$ as ptr, 1028 as long, 0
                            as long, r as long
                            buffer$=left$(buffer$, instr(buffer$, chr$(0)) - 1)
                            if r>0 then
                            mciSendString$="error"
                            else
                            mciSendString$=buffer$
                            end if
                            end Function

                            function MakeHMS$(milliseconds)
                            minutes = int(milliseconds / (1000 * 60))
                            seconds = int((milliseconds - minutes * 60) / 1000)
                            MakeHMS$ = right$("00"; minutes, 2); ":"; right$("00"; seconds, 2)
                            end function

                            function GetSongTitle$(song$)
                            songEnd$ = right$(song$, 5)
                            songEnd = instr(song$, songEnd$)
                            GetSongTitle$ = left$(song$, songEnd)
                            end function




                            Yahoo! Groups Links
                          Your message has been successfully submitted and would be delivered to recipients shortly.