Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

My own version of an MP3 player

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • My own version of an MP3 player

    Deleted in flavor of the updated version.


    [This message has been edited by Mel Bishop (edited February 16, 2007).]
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

  • #2
    Code:
    REM ********************************************************************
    REM * Updates and notes:                                               *
    REM * Volume control added. Press +/= to increase, -/_ to decrease.    *
    REM * Pirated from Ralph Bing at:                                      *
    REM * [URL="http://www.powerbasic.com/support/pbforums/../forums/Forum5/HTML/003440.html"]http://www.powerbasic.com/support/forums/Forum5/HTML/003440.html[/URL]  *
    REM *                                                                  *
    REM * Drag-n-drop a single tune now documented. Forgot to mention that *
    REM * before. Oops!                                                    *
    REM *                                                                  *
    REM * Prevent program from running more than one at a time.            *
    REM * I can't remember/find where I got this routine from so please    *
    REM * accept my apologies.                                             *
    REM *                                                                  *
    REM * I thought I had restricted this to MP3 files only but, come to   *
    REM * find out, it seems to play .WAV files just fine. Hmmmmm. So if   *
    REM * you rip a tune from a CD, save it to a fixed rate .MP3 or .WAV ≤="; *
    REM * file.                                                            *
    REM *                                                                  *
    REM * This program has trouble with variable bit rate files. It will   *
    REM * sometimes abort the file someplace before the tune actually ends.*
    REM * I don't think it's a problem with this program but with how      *
    REM * MCISENDSTRING digests variable bit rates.                        *
    REM ********************************************************************
    REM * Be sure to read the REM statements at the SelectFile SUB at the  *
    REM * tail end of this source code. It's important!!!                  *
    REM ********************************************************************
    REM * I wanted an MP3 player to play only selected tunes as my mood    *
    REM * dictates. I think WMP can do this but where's the fun in that!!  *
    REM ********************************************************************
    REM * This is a work in progress but it seems to be okay for now.      *
    REM *                                                                  *
    REM * One of the things I need to work on is the number of tunes per   *
    REM * file. Currently, it's restricted to a maximum of 30 due to no    *
    REM * scrolling (due to the progress bar) but I'm working on that.     *
    REM ********************************************************************
    REM * The tune manipulation code was lifted from Errol Cheverie at:    *
    REM * [URL="http://www.powerbasic.com/support/pbforums/../forums/Forum7/HTML/000920.html"]http://www.powerbasic.com/support/forums/Forum7/HTML/000920.html[/URL]  *
    REM * Thanks.                                                          *
    REM ********************************************************************
    REM * Since I play exclusively MP3 files, I deleted all references to  *
    REM * other file formats and completely replaced PBMAIN().             *
    REM ********************************************************************
    REM * F-1 = "Help" Screen                                              *
    REM ********************************************************************
                                                        '
    #INCLUDE "comdlg32.inc"                             '
    #INCLUDE "Win32api.inc"                             '
                                                        '
        DECLARE FUNCTION Is_Already_Running(TitleName AS ASCIIZ)AS LONG
        DECLARE FUNCTION mmGetLengthT    () AS STRING   '
        DECLARE FUNCTION mmGetLengthM    () AS LONG     '
        DECLARE FUNCTION mmGetPositionT  () AS STRING   '
        DECLARE FUNCTION mmGetPositionM  () AS LONG     '
        DECLARE FUNCTION ToTime    (LONG)   AS STRING   '
        DECLARE FUNCTION mmOpen    (STRING) AS LONG     '
                                                        '
        DECLARE SUB mmPlay              (LONG)          '
        DECLARE SUB mmSeek              (LONG)          '
        DECLARE SUB SetPositionM        (LONG)          '
        DECLARE SUB SelectFile                          '
        DECLARE SUB SetVolumeLevel                      '
        DECLARE SUB Delay(DelayTime AS SINGLE)          '
        DECLARE SUB SeekLeft                            '
        DECLARE SUB SeekRight                           '
                             ass=;nbsp;                          '
        DECLARE SUB mmPause             ()              '
        DECLARE SUB mmResume            ()              '
        DECLARE SUB mmStop              ()              '
        DECLARE SUB mmClose                             '
        DECLARE SUB Shuffle                             '
        DECLARE SUB ShowTunes                           '
        DECLARE SUB tProgress                           '
        DECLARE SUB HelpScreen                          '
                                                        '
        GLOBAL gsAlias       AS STRING                  '
        GLOBAL tune()        AS STRING                  '
        GLOBAL folder        AS STRING                  '
                                                        '
        GLOBAL row           AS LONG                    '
        GLOBAL i             AS LONG                    '
        GLOBAL total         AS LONG                    '
        GLOBAL progress      AS LONG                    '
        GLOBAL OldProg       AS LONG                    '
        GLOBAL iPosition     AS LONG                    '
        GLOBAL iCurrMediaPos AS LONG                    '
        GLOBAL nPos          AS LONG                    '
        GLOBAL NewVolume$                               '
                                                        '
    FUNCTION PBMAIN () AS LONG                          '
        LOCAL sFileName    AS STRING                    '
        LOCAL OldPos       AS STRING                    '
        LOCAL NewPos       AS STRING                    '
        LOCAL sLength      AS STRING                    '
        LOCAL te           AS STRING                    '
        LOCAL NewTime      AS STRING                    '
        LOCAL OldTime      AS STRING                    '
                                                        '
        LOCAL iRetCode     AS LONG                      '
        LOCAL x            AS LONG                      '
        LOCAL y            AS LONG                      '
        LOCAL tCommandFlag AS LONG                      '
        LOCAL CurrVol&                                  '
                                                        '
        GLOBAL TitleName AS ASCIIZ * 15                 '
        GLOBAL hMutex AS LONG                           '
                                                        '
        COLOR 14,1                                      '
        CLS                                             '
                                                        '
        Title$ = "Mel's MP3 Player v2.0"                '
        CONSOLE NAME Title$                             '
        TitleName = Title$                              ' This MUST match the console
                                                        ' name.
        IF Is_already_running(BYCOPY title$) THEN       ' If it's already running,
        CLS                                             ' abort after a 5-second
        m$ = Title$ + " is already running."            ' display time.
        LOCATE 5,40 - INT(LEN(m$) / 2)                  '
        PRINT;m$;                                       '
        delay 2                                         '
        EXIT FUNCTION                                   '
        END IF                                          '
                                                        '
        CurrVol& = 500                                  ' Set default volume
        NewVolume$ = USING$("###",CurrVol&)             '
                                                        '
        CONSOLE SCREEN 31,80                            '
        CURSOR OFF                                      '
        tCommand$ = COMMAND$                            '       Drag-n-drop and single tune.
        DO                                              '<----: Master loop
        CLS                                             '     |
        IF tCommand$ = "" THEN                          '<:   |
        SelectFile                                      ' |   |
        IF folder = "" THEN EXIT FUNCTION               ' |   |
        shuffle                                         ' |   |
        ELSE                                            '<:   |
        tCommandFlag = 1                                ' |   |
        i = 1                                           ' |   |
        REDIM PRESERVE tune(i)                          ' |   |
        tune(i) = REMOVE$(tCommand$,CHR$(34))           ' |   |
        tCommand$ = ""                                  ' |   |
        END IF                                          '<:   |
                                                        '     |
        LOCATE 31,1 : PRINT;"(P)ause ";                 '     |
        ShowTunes                                       '     |
        row = 0                                         '     |
        x   = 0                                         '     |
                                                        '     |
    REM *****************************                   '     |
    REM * Now play them in sequence *                   '     |
    REM *****************************                   '     |
                                                        '     |
        DO                                              '<---:|
        Progress = 0                                    '    | | Blank out the
        Total    = 0                                    '    | | progress bar.
                                                        '    | |
        LOCATE 31,15                                    '    | | Show basic progress
        PRINT;STRING$(50,249);                          '    | | bar.
                                                        '    | |
        INCR x                                          '    | |
        IF x > i THEN                                   '<:  | | At end of stack.
        x = 1                                           ' |  | | Roll over back to
        LOCATE row,1 : PRINT;SPACE$(2);                 ' |  | | the top.
        row = x - 1                                     ' |  | |
        END IF                                          '<:  | |
                                                        '    | |
        INCR row                                        '    | |
        IF row > 1 THEN                                 '<:  | |
        LOCATE row-1,1                                  ' |  | |
        PRINT;SPACE$(2);                                ' |  | |
        END IF                                          '<:  | |
        LOCATE row,1                                    '    | |
        PRINT;">";                                      '    | |
                                                        '    | |
        sFileName = folder + tune(x)                    '    | |
        iRetCode = mmOpen(sFileName)                    '    | |
                                                        '    | |
    REM ************************************************'    | |
    REM * Set the initial volume control value. If you *'    | |
    REM * change the default from 400 to, say 300, the *'    | |
    REM * tune will play at 300 but then blow back to  *'    | |
    REM * 400 for the next tune.                       *'    | |
    REM ************************************************'    | |
                                                        '    | |
        SetVolumeLevel                                  '    | | Set volume to current value
        CALL mmPlay(0&)                                 '    | |
        sLength = mmGetLengthT                          '    | |
                                                        '    | |
        LOCATE 30,73                                    '    | | Show total length of
        PRINT;ToTime(mmGetLengthM / 1000);              '    | | tune in HH:MM:SS format
                                                        '    | |
        DO                                              '<--:| | Allow the tune to play
                                                        '   | ||
        WHILE INSTAT = 0                                '<-:| ||
        NewPos = mmGetPositionT                         '  | || | Current position.
                                                        '  | || |
        NewTime = ToTime(mmGetPositionM / 1000)         '  | || |
        IF NewTime <> OldTime THEN                      '<:| || | Show elapsed time only
        LOCATE 31,73                                    ' | || || when it changes.
        PRINT;NewTime;                                  ' | || || HH/MM/SS format.
        OldTime = NewTime                               ' | || ||
        END IF                                          '<:| || |
                                                        '  | || |
        IF NewPos = sLength THEN EXIT, EXIT             '  | || | If a match, it's finished.
        tProgress                                       '  | || |
        SLEEP 0                                         '  | || |
        WEND                                            '<-:| ||
        an$ = INKEY$                                    '   | ||
                                                        '   | ||
        IF an$ <> "" THEN                               '<-:| ||
                                                        '  | || |
        an$ = UCASE$(an$)                               '  | || |
                                                        '  | || |
        IF an$ = CHR$(0,59) THEN HelpScreen             '  | || | F-1 Help screen
                                                        '  | || |
        IF an$ = "P" THEN                               '<:| || | Pause play
        LOCATE 31,1                                     ' | || ||
        PRINT;"(R)esume";                               ' | || ||
        mmPause                                         ' | || ||
        END IF                                          '<:| || |
                                                        '  | || |
        IF an$ = "R" THEN                               '<:| || | Resume play
        LOCATE 31,1                                     ' | || ||
        PRINT;"(P)ause ";                               ' | || ||
        mmResume                                        ' | || ||
        END IF                                          '<:| || |
                                                        '  | || |
        IF an$ = "S" THEN                               '<:| || | Shuffle the deck.
        Shuffle                                         ' | || ||
        ShowTunes                                       ' | || ||
        x = x - 1                                       ' | || ||
        IF x < 1 THEN x = 0                             ' | || ||
        row = x                                         ' | || ||
        EXIT                                            ' | || ||
        END IF                                          '<:| || |
                                                        '  | || |
        IF an$ = CHR$(0,72) THEN                        '<:| || | Cursor up. Previous tune.
        x = x - 2                                       ' | || ||
        IF x < 1 THEN x = i                             ' | || ||
        LOCATE row,1 : PRINT;SPACE$(2);                 ' | || ||
        row = x                                         ' | || ||
        EXIT                                            ' | || ||
        END IF                                          '<:| || |
                                                        '  | || |
        IF an$ = CHR$(0,80) THEN                        '<:| || | Cursor down. Next tune.
        EXIT                                            ' | || ||
        END IF                                          '<:| || |
                                                        '  | || |
        IF an$ = CHR$(0,75) THEN SeekLeft               '<:| || | Cursor left
                                                        '  | || |
        IF an$ = CHR$(0,77) THEN SeekRight              '<:| || | Cursor right
                                                        '  | || |
        IF an$ = "+" OR an$ = "-" OR an$ = "=" THEN     '  | || |
                                                        '  | || |
        IF an$ = "+" OR an$ = "=" THEN                  '<:| || | Volume Up
        CurrVol& = CurrVol& + 25                        ' | || || Anywhere from 0 to 1000
        IF currvol	 	;amp; > 1000 THEN currvol& = 1000         ' | || || The original value of step 50
        ELSE                                            '<:| || | was a little too abrupt for me
        CurrVol& = CurrVol& - 25                        ' | || || Volume down
        IF currvol& < 00 THEN currvol& = 0              ' | || ||
        END IF                                          '<:| || |
                                                        '  | || |
        NewVolume$ = USING$("####",CurrVol& )           '  | || |
        SetVolumeLevel                                  '  | || |
        END IF                                          '  | || |
                                                        '  | || |
        IF an$ = CHR$(27) THEN                          '  | || |
        mmstop                                          '  | || |
        mmclose                                         '  | || |
        EXIT, EXIT                                      '  | || |
        END IF                                          '  | || |
        END IF                                          '<-:| ||
                                                        '   | ||
        LOOP                                            '<--:| |
        mmStop                                          '    | |
        mmClose                                         '    | |
        IF tCommandFlag = 1 THEN EXIT FUNCTION          '    | |
        LOOP                                            '<---:|
        LOOP                                            '<----: /Master loop
                                                        '
    END FUNCTION                                        '
                                                        '
    FUNCTION mmOpen(sFileName AS STRING) AS LONG        '
        LOCAL szLongPath  AS ASCIIZ * %MAX_PATH + 1     '
        LOCAL szShortPath AS ASCIIZ * %MAX_PATH + 1     '
        LOCAL iRetCode    AS LONG                       '
        LOCAL sCmd        AS STRING                     '
        LOCAL sType       AS STRING                     '
                                                        '
        IF LEN(gsAlias) THEN CALL mmClose               '
                                                        '
        sType = "mpegvideo"                             '
        gsAlias = RIGHT$(sFileName, 3) + _              '
                  TRIM$(STR$(VAL(MID$(TIME$, 4, 2))))   '
        szLongPath = sFileName                          '
        GetShortPathName(BYVAL VARPTR(szLongPath) ,_    '
                         BYVAL VARPTR(szShortPath),_    '
                        %MAX_PATH + 1)                  '
                                                        '
        iRetCode = mciSendString("Open "       + _      '
                                   szShortPath + _      '
                                 " ALIAS "     + _      '
                                   gsAlias     + _      '
                                 " TYPE "      + _      '
                                   sType       + _      '
                                 " wait", "", _         '
                                  %NULL, %NULL)         '
        FUNCTION = iRetCode                             '
        END FUNCTION                                    '
                                                        '
    SUB mmClose()                                       '
        LOCAL iRetCode AS LONG &ing:nbsp;                        '
                                                        '
        iRetCode = mciSendString("Close " + _           '
                                  gsAlias, "", _        '
                                  %NULL, %NULL)         '
        gsAlias = ""                                    '
        END SUB                                         '
                                                        '
    SUB mmPlay(iwait AS LONG)       &amphp?gp;                   '
        LOCAL iRetCode AS LONG                          '
                                                        '
        iRetCode = mciSendString("Play "     + _        '
                                  gsAlias, "", _        '
                                  %NULL, %NULL)         '
        END SUB                                         '
                                                        '
    SUB mmPause()                                       '
        CALL mciSendString("Pause "    + _              '
                            gsAlias, "", _              '
                            %NULL, %NULL)         &n         '
        END SUB                                         '
                                                        '
    SUB mmResume()                                      '
        LOCAL iRetCode AS LONG                          '
                                                        '
        iRetCode = mciSendString("Resume "   + _        '
                                  gsAlias, "", _        '
                                  %NULL, %NULL)         '
        END SUB                                         '
                                                        '
    SUB mmStop()                                        '
        CALL mciSendString("Stop " + _                  '
                            gsAlias, "", _              '
                            %NULL, %NULL)               '
        END SUB                                         '
                                                        '
    SUB mmSeek(iPosition AS LONG)                       '
        CALL mciSendString("Seek " + gsAlias + _        '
                           " to " + STR$(iPosition), _  '
                           "", %NULL, %NULL)            '
        END SUB                                         '
                                                        '
    SUB SetPositionM(iPosition AS LONG)                 '
        CALL mmSeek(iPosition)                          '
                                                        '
        END SUB                                         '
                                                        '
    FUNCTION mmGetLengthM() AS LONG                     '
        LOCAL iMediaLength AS LONG                      '
        LOCAL szLength AS ASCIIZ * 255                  '
                                                        '
        CALL mciSendString("Status " + _                '
                            gsAlias  + _                '
                           " length",  _                '
                           szLength, 255, %NULL)        '
        FUNCTION = CLNG(VAL(szLength))                  '
        END FUNCTION                                    '
                                                        '
    FUNCTION mmGetLengthT() AS STRING                   '
        LOCAL sMP3Time      AS STRING                   '
        LOCAL iMediaLength  AS LONG                     '
        LOCAL szLength      AS ASCIIZ * 255             '
                                                        '
        CALL mciSendString("Status " + _                '
                            gsAlias  + _                '
                           " length",  _                '
                            szLength, 255, %NULL)       '
        iMediaLength = CLNG(VAL(szLength))              '
                                       td> ;nbsp;                '
        Total = iMediaLength                            '  For progress bar.
                                                        '
        iMediaLength = iMediaLength \ 1000              '
        sMP3Time = TRIM$(STR$(iMediaLength \ 60))       '
        sMP3Time = sMP3Time + ":" + RIGHT$(TRIM$(STR$(100 + (iMediaLength MOD 60))), 2)
        FUNCTION = sMP3Time                             '
        END FUNCTION                                    '
                                                        '
    FUNCTION mmGetPositionM() AS LONG                   '
        LOCAL szPosition      AS ASCIIZ * 255           '
        LOCAL iRetCode        AS LONG                   '
                                                        '
        iRetCode = mciSendString("Status "      + _     '
                                  gsAlias       + _     '
                                 " position",     _     '
                                 szPosition, 255, _     '
                                 %NULL)                 '
        FUNCTION = VAL(szPosition)                      '
        END FUNCTION                                    '
                                                        '
    FUNCTION mmGetPositionT() AS STRING                 '
        LOCAL szPosition    AS ASCIIZ * 255             '
        LOCAL sElapsed      AS STRING                   '
        LOCAL iCurrMediaPos AS LONG                     '
        LOCAL iRetCode      AS LONG                     '
                                                        '
        iRetCode = mciSendString("Status "  + _         '
                                  gsAlias   + _         '
                                 " position", _         '
                                  szPosition, _         '
                                         255, _         '
                                       %NULL)           '
        iCurrMediaPos = CLNG(VAL(szPosition))           '
        progress = iCurrMediaPos                        ' Progress bar.
        iCurrMediaPos = iCurrMediaPos \ 1000            '
        sElapsed = TRIM$(STR$(iCurrMediaPos \ 60))      '
        sElapsed = sElapsed + ":" + RIGHT$(TRIM$(STR$(100 + (iCurrMediaPos MOD 60))), 2)
        FUNCTION = sElapsed                             '
        END FUNCTION                                    '
                                                        '
    SUB Shuffle                                         '
        LOCAL x  AS LONG                                '
        LOCAL t1 AS LONG                                '
        LOCAL t2 AS LONG                                '
        RANDOMIZE TIMER                                 '
                                                        '
        FOR x = 1 TO i                                  '<-: Select the 1st tune.
        t1 = 0                                          '  |
        DO UNTIL t1 > 0 AND (t1 < (i + 1))              '<:|
        t1 = INT(RND(1,i))                              ' | |
        LOOP                                            '<:|
                                                        '  |
        t2 = 0                                          '  | Select the 2nd tune.
        DO UNTIL t2 > 0 AND (t2 < (i + 1)) AND t2 <> t1 '<:|
        t2 = INT(RND(1,i))                              ' | |
        LOOP                                            '<:|
                                                        '  |
        SWAP tune(t1), tune(t2)                         '  |
        NEXT x                                          '<-:
        END SUB                                         '
                                                        '
    SUB ShowTunes                                       '
        LOCAL saverow AS LONG                           '
                                                        '
        saverow = row                                   '
        FOR row = 1 TO i                                '<:
        LOCATE row,3                                    ' |
        PRINT;tune(row) + SPACE$(81 - LEN(tune(row)));  ' |
        NEXT row                                        '<:
        row = saverow                                   '
        END SUB                                         '
                                                        '
    SUB tProgress                                       ' Update the progress
        LOCAL te AS LONG                                ' bar.
        LOCAL OnePercent AS LONG                        '
                                                        '
        OnePercent = progress / (total / 100)           '
        LOCATE 31,65                                    '
        PRINT;USING$("###",Onepercent);"%";             '
                                                        '
        te = ((progress / (total / 100)) / 2)           ' In 2-percent increments.
        IF te = oldprog THEN EXIT SUB                   '
        LOCATE 31,15                                    '
        PRINT;STRING$(te,178) + STRING$(50-te,249); _   '
        USING$("###",te * 2);"%";                       '
        oldprog = te                                    '
        END SUB                                         '
                                                        '
    SUB HelpScreen                                      '
                                                        '
        PCOPY 1,2                                       ' Save contents.
        CLS                                             '
        LOCATE  3, 3                                    '
        PRINT;"Cursor up    = Previous tune.";          '
                                                        '
        LOCATE  5, 3                                    '
        PRINT;"Cursor down  = Next tune.";              '
                                                        '
        LOCATE  7, 3                                    '
        PRINT;"Cursor right = Step right in tune.";     '
                                                        '
        LOCATE  9, 3                                    '
        PRINT;"Cursor left  = Step left in tune.";      '
                                                        '
        LOCATE 11, 3                                    '
        PRINT;"S key = Shuffle the deck."               '
                                                        '
        LOCATE 13, 3                                    '
        PRINT;"ESCape to select new file."              '
                                                        '
        LOCATE 15,3                                     '
        PRINT;"+ or = to increase volume."             &ampw">Rp;'
                                                        '
        LOCATE 17,3                                     '
        PRINT;"- or _ to decrease volume."              '
                                                        '
        LOCATE  3,40                                    '
        PRINT;"Drag-n-Drop a single tune if you want."  '
                                                        '
        m$ = "Press any key to return."                 '
        LOCATE 30,40 - INT(LEN(m$) / 2)                 '
        PRINT;m$;                                       '
                                                        '
        WAITKEY$                                        '
        PCOPY 2,1                                       ' Restore contents.
        END SUB                                         '
                                                        '
                                                        '
    REM *********************************************** '
    REM * Convert seconds to time (HH:MM:SS) format   * '
    REM * Since the Rush Limbaugh show lasts for      * '
    REM * almost two hours, I needed to include hours * '
    REM *********************************************** '
                                                        '
    FUNCTION ToTime(tSeconds AS LONG) AS STRING         '
        LOCAL hours   AS LONG                           '
        LOCAL minutes AS LONG                           '
        LOCAL seconds AS LONG                           '
        LOCAL t       AS LONG                           '
                                                        '
        t = tSeconds                                    '
                                                        '
        hours = t \ 3600                                ' Extract hour(s)
        t = t - (hours * 3600)                          '
        minutes = t \ 60                                ' Extract minutes
        seconds = t - (minutes * 60)                    ' then seconds.
                                                        '
        te$ = USING$("##:",hours) + _                   '
              USING$("##:",minutes) + _                 '
              USING$("##",seconds)                      '
        REPLACE " " WITH "0" IN te$                     '
        FUNCTION = te$                       &nbid="         '
        END FUNCTION                                    '
                                                        '
    REM ********************************                '
    REM * Increase/Decrease the volume *                '
    REM ********************************                '
                                                        '
    SUB SetVolumeLevel                                  '
          LOCATE 29,71                                  '
          PRINT;"Vol = "+USING$("####",VAL(newvolume$));'
          mciSendString "setaudio " + _                 '
                      $DQ + gsAlias + _                 '
                      $DQ + _                           '
                      " volume to " + _                 '
                      NewVolume$,   _                   '
                      "", 0, 0                          '
        END SUB                                         'FUNCTION Is_Already_Running(TitleName AS ASCIIZ) EXPORT AS LONG
        LOCAL hMutex AS LONG
        hMutex = CreateMutex(BYVAL %Null, 0, TitleName)
        IF hMutex = 0 THEN EXIT FUNCTION                ' Error in Mutex
        IF GetLastError = %ERROR_ALREADY_EXISTS OR FindWindow(TitleName, "") > 0 THEN
        FUNCTION = %TRUE
        END IF
        END FUNCTION
                                                        '
    SUB Delay(DelayTime AS SINGLE)                      '
        LOCAL StartTime  AS DOUBLE                      '
        LOCAL EndTime    AS DOUBLE                      '   Time to finish
                                                        '
        StartTime = TIMER                               '
        EndTime = StartTime + DelayTime                 '   Add the delay.
                                                        '
        IF EndTime > 86400 THEN                         '<: Wrap-Around
        EndTime = EndTime - 86400                       ' | at midnight.
        END IF                                          '<:
                                                        '
        DO UNTIL StartTime => EndTime                   '   Keep looping until.....
        IF INKEY$ <> "" THEN EXIT SUB                   '   Premature abort.
        StartTime = TIMER                               '
        SLEEP 0                                         '
        LOOP                                            '
        END SUB                                         '
                                                        '
    SUB SeekLeft                                        '
        mmPause                                         ' Seek left.
        nPos = mmGetPositionM - ((total / 100) * 3)     '
        IF nPos < 0 THEN nPos = 0                       '
        setpositionm(nPos)                              '
        tProgress                                       '
        mmPlay(0&)                                      '
        END SUB                                         '
                                                        '
    SUB SeekRight                                       '
        mmPause                                         ' Seek right.
        nPos = mmGetPositionM + ((total /100) * 5)      '
     &ampSTRIp;  IF nPos => total THEN nPos = total - 1000       '
        IF nPos < 0 THEN nPos = 0                       '
        setpositionm(nPos)                              '
        mmPlay(0&)                                      '
        END SUB                                         '
                                                        '
    REM *********************************************** '
    REM * This routine opens a plain ASCII text file  * '
    REM * containing the info needed to play tunes.   * '
    REM *********************************************** '
    REM *                                             * '
    REM * Do NOT use quotes to wrap path/file name(s) * '
    REM *                                             * '
    REM *********************************************** '
    REM *                                             * '
    REM * The first line must be the full path to     * '
    REM * where the tunes are located. After that are * '
    REM * the file name(s) of the tunes to be played. * '
    REM *                                             * '
    REM * An example file might look like this:       * '
    REM * The file name would be "HardRock.dat"       * '
    REM * or anything you like.             &amref=sp;         * '
    REM *                                             * '
    REM * d:\mp3\                                     * ' Full path
    REM * in-a-gadda-da-vida.mp3                      * ' Tune name 1
    REM * layla.mp3                                   * ' Tune name 2
    REM * Telstar.mp3                                 * ' Tune name 3
    REM * The Final Countdown.mp3                     * ' Tune name 4, etc.
    REM *                                             * ' up to a max of 30
    REM * The advantage to this is that all your      * ' tunes.
    REM * tunes can still be located in one folder.   * '
    REM *********************************************** '
                                                        '
    SUB SelectFile                                      '
        LOCAL txt AS STRING                             '
        LOCAL f1  AS STRING                             '
        LOCAL x AS LONG                                 '
        folder = ""                                     '
        i = 0                                           '
                                                        '
        LOCAL result AS STRING                          '
        LOCAL path   AS STRING                          '
        LOCAL style  AS LONG                            '
                                                        '
        txt = "MP3 .Dat files                           '
        OpenFileDialog(0, txt, f1, Path, txt + "|*.dat|All Files|*.*", "txt", Style)
        IF f1 = "" THEN EXIT SUB                        '
        OPEN f1 FOR INPUT AS #1                         '
        LINE INPUT #1,folder                            '
                                                        '
        IF RIGHT$(folder,1) <> "\" THEN                 '<: Just in case
        folder = folder + "\"                           ' |
        END IF                                          '<:
                                                        '
        i = 0                                           '
                                                        '
        DO UNTIL EOF(1)                                 '<--:
        LINE INPUT #1,te$                               '   |
        IF te$ <> "" THEN                               '<-:| Ignore blank lines.
        t$ = DIR$(folder + te$)                         '  | |
        IF t$ <> "" THEN                                '<:| | If the file actually
        INCR i                                          ' | || exists...
        REDIM PRESERVE tune(i)                          ' | ||
        tune(i) = te$                                   ' | ||
        END IF                                          '<:| |
        END IF                                          '<-:|
                                                        '   |
        IF i = 30 THEN EXIT LOOP                        '   |
        LOOP                                            '<--:
        CLOSE #1                                        '
        END SUB
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

    Comment

    Working...
    X