Announcement

Collapse
No announcement yet.

About MP3 again

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

  • About MP3 again

    I am trying to use either mcisendstring or mcicommand to play MP3 files.
    But everything i tried failed (I do have the latest Media Player 7.0
    already installed on my computer)

    Does some of you have been able to play such files in PB/DLL?

    Would you be so kind to share your knowledge with me



    ------------------
    Patrice Terrier
    mailto[email protected][email protected]</A>
    Patrice Terrier
    www.zapsolution.com
    www.objreader.com
    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

  • #2
    Patrice,

    I'm writing an MP3 PLAYER myself and so far I have no problems, I'm
    using mciSendString, I'm running it on a Win98, WinME, Win2k and
    plays beautifully (there are some problems here and there) but THEY
    CAN BE PLAYED, what is exactly the problem you're having?.
    One thing I have noticed though, SOME MP3's can't be played using
    mciSendString <scratching my head>
    BTW, the code is written in PBDLL60.

    ------------------
    Ivan

    Uncle Droid (Android Apps)

    Comment


    • #3
      Ivan,

      I am using this syntax:

      DIM zMP3 AS ASCIIZ * %OFS_MAXPATHNAME
      zMP3 = "g:\mp3\THE_AB~1.mp3"
      Ret& = mciSendString("Open " + zMP3, BYVAL %NULL, BYVAL %NULL, BYVAL %NULL)
      Ret& = mciSendString("Play " + zMP3, BYVAL %NULL, BYVAL %NULL, BYVAL %NULL)

      but it doesn't play anything.
      The same song plays just fine in Windows Media Player 7.0

      Could you send me the Open and Play syntax you are using yourself?




      ------------------
      Patrice Terrier
      mailto[email protected][email protected]</A>
      Patrice Terrier
      www.zapsolution.com
      www.objreader.com
      Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

      Comment


      • #4
        Patrick,

        This is how I play the MP3s:

        mciSendString "Open "+MP3Name$,"",%null,%null
        mciSendString "Play "+MP3Name$,"",%null,%null
        mciSendString "Pause "+MP3Name$,"",%null,%null
        mciSendString "Stop "+MP3Name$,"",%null,%null

        Those are the basic controls, and you have to have the latest
        Windows media player installed (some Win98 machines might not
        play them).

        I hope this helps.



        ------------------
        Ivan

        Uncle Droid (Android Apps)

        Comment


        • #5
          Ivan,

          It is almost the same code that I am using myself.
          Would it be possible for you to send me a small MP3 file that works
          with this code.
          I would like to test it with my own system configuration.
          Please send it at:

          [email protected]

          Thank you



          ------------------
          Patrice Terrier
          mailto[email protected][email protected]</A>
          Patrice Terrier
          www.zapsolution.com
          www.objreader.com
          Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

          Comment


          • #6
            Patrice

            Here is some code that I downloaded from the PowerBASIC for Windows form that Timm Motl
            posted on September 16, 2000 12:38 AM

            mciSendString seems to need a short path and filename
            changed Timm code to call the API function GetShortPathName() with the path and file name
            it seems to work just fine on my Win2K system.


            Code:
            #COMPILE EXE
            #REGISTER NONE
            #INCLUDE "WIN32API.INC"
            
            GLOBAL hDlg AS LONG
            GLOBAL MP3Playing AS LONG
            GLOBAL MP3FileName AS STRING
            
            
            '========================================================================================================================
            CALLBACK FUNCTION DlgProc
               SELECT CASE CBMSG
               CASE %WM_DESTROY
                  mciSendString "close " + MP3FileName, "", %NULL, %NULL
               END SELECT
            
               SELECT CASE CBCTLMSG
               CASE %BN_CLICKED
                  SELECT CASE CBCTL
                  CASE 100
                     IF MP3Playing THEN
                        MP3Playing = 0
                        CONTROL SET TEXT hDlg, 100, "Start"
                        mciSendString "close " + MP3FileName, "", %NULL, %NULL
                     ELSE
                        MP3Playing = 1
                        CONTROL SET TEXT hDlg, 100, "Stop"
                        mciSendString "open " + MP3FileName, "", %NULL, %NULL
                        mciSendString "play " + MP3FileName, "", %NULL, %NULL
                     END IF
                  END SELECT
               END SELECT
            END FUNCTION
            
            '========================================================================================================================
            
            FUNCTION PBMAIN
            
            LOCAL lpszLongPath  AS ASCIIZ * %MAX_PATH + 1   ' points to a null-terminated path string
            LOCAL lpszShortPath AS ASCIIZ * %MAX_PATH + 1   ' points to a buffer to receive the null-terminated short form of the path
            LOCAL cchBuffer     AS DWORD                ' specifies the size of the buffer pointed to by lpszShortPath
            
            
            '************************************************
            ' Note:
            ' mciSendString needs a short filename, path
            '************************************************
            
            ' *** Change to whatever ***
            lpszLongPath = "D:\MP3S\Country\Red Sovine\Red Sovine- Bringing Mary Home.mp3"
            IF GetShortPathName(BYVAL VARPTR(lpszLongPath), BYVAL VARPTR(lpszShortPath), %MAX_PATH + 1) THEN
                MP3FileName = lpszShortPath
            ELSE
                MSGBOX "GetShortPathName for " + lpszLongPath + " returned an error ** Path or FileName Not Found **"
                EXIT FUNCTION
            END IF
            
            DIALOG NEW 0, "MP3 Player",,, 100, 50, %WS_SYSMENU + %WS_MINIMIZEBOX TO hDlg
            CONTROL ADD BUTTON, hDlg, 100, "Start", 30, 10, 40, 15, %BS_DEFAULT
            DIALOG SHOW MODAL hDlg CALL DlgProc
            
            END FUNCTION
            Regards Errol

            ------------------

            Comment


            • #7
              Patrice, as I see, already used short name.
              mciSendString returns zero if successful or an error otherwise.
              The low-order word of the returned DWORD value contains the error return value. If the error is device-specific, the high-order word of the return value is the driver identifier; otherwise, the high-order word is zero.
              To retrieve a text description of mciSendString return values, it's necessary to pass the return value to the mciGetErrorString function.


              ------------------
              E-MAIL: [email protected]

              Comment


              • #8
                Dear Ivan and Others,

                Thank you very much for the MP3 song example you sent to me.

                I can't play it either.

                I did my test on both Windows 98 First Edtion and Windows 2000.

                With Windows 98 i have installed Windows Media Player 7.0 that
                is able to play MP3 just fine.

                But none of the MCI command i have been playing with has been
                able to play a MP3 song on my computer.

                Have you ever heard of the freeware BLADE.DLL to play MP3?

                Thank you again



                ------------------
                Patrice Terrier
                mailto[email protected][email protected]</A>
                Patrice Terrier
                www.zapsolution.com
                www.objreader.com
                Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                Comment


                • #9
                  Following Semen suggestion i did check for the error

                  I get a MMSYSTEM263 error "Unknown MCI device".

                  Do you know what should be installed in order to play MP3 with the MCI?

                  Installing Windows Media Player 7.0 does not allow MCI to play MP3
                  we need something else (MPEG encoder/decoder?)


                  ------------------
                  Patrice Terrier
                  mailto[email protected][email protected]</A>
                  Patrice Terrier
                  www.zapsolution.com
                  www.objreader.com
                  Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                  Comment


                  • #10
                    After a few hours search,
                    i found myself the solution to play correctly MP3 files.

                    The secret, of course but not obvious, is to use the good "Open" syntax,
                    see the example in the programming section.



                    ------------------
                    Patrice Terrier
                    mailto[email protected][email protected]</A>
                    Patrice Terrier
                    www.zapsolution.com
                    www.objreader.com
                    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                    Comment


                    • #11
                      Patrice --
                      Type MPEGVIDEO is not a reserved word.
                      At least current MSDN talks:
                      MCI reserves "cdaudio" for the CD audio device type,
                      "videodisc" for the videodisc device type,
                      "sequencer" for the MIDI sequencer device type,
                      "AVIVideo" for the digital-video device type, and
                      "waveaudio" for the waveform-audio device type.

                      I'm not surprised that this solution works on YOUR PC, because "
                      As an alternative to the "type" flag, MCI can select the device based on the extension used by the file, as recorded in the registry or the [mci extension] section of the SYSTEM.INI file."

                      But not sure that it works on ANY PC.



                      ------------------
                      E-MAIL: [email protected]

                      Comment


                      • #12
                        Semen--

                        After doing lots of search, here is what i found:

                        IF you use AVI files Then you have to use
                        typeDevice$ = "AviVideo"
                        ELSEIF you use MPG, MP3, MP2, MP1, WAV,,,etc
                        typeDevice$ = "MPEGVideo"
                        END IF

                        "open " + FileShortName$ + " Type " + typeDevice$ + " Alias AliasNAME"




                        ------------------
                        Patrice Terrier
                        mailto[email protected][email protected]</A>
                        Patrice Terrier
                        www.zapsolution.com
                        www.objreader.com
                        Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                        Comment


                        • #13
                          Well, since we are all in a roll regarding MP3s, I have a couple of
                          questions myself.

                          The MP3 player I'm writing is ALMOST done (you can SKIN it, sort,
                          shuffle MP3s, search for MP3, add/remove, etc) but the problem I'm
                          having is that I DON'T KNOW how to get the STATUS of the file (how
                          big is it, is it done?, etc), therefore I can't play them in sequence
                          (like a jukebox), I've tried examples found but I've been unable
                          to UNDERSTAND them, most of them for VB5 but very confusing, so,
                          if any of you guys have experience in this matter, PLEASE share
                          it with me

                          thanks a bunch.

                          Ivan

                          ------------------
                          Ivan

                          Uncle Droid (Android Apps)

                          Comment


                          • #14
                            Ivan...

                            To get an MP3 file's length in 0:00 time format, use the following commands...
                            Code:
                            LOCAL ReturnString AS ASCIIZ * 256
                            
                            
                            MP3FileName = CHR$(34) + "C:\MY MUSIC\MY MP3 FILENAME.MP3" + CHR$(34)
                            mciSendString "open " + MP3FileName + " alias MP3", "", 0, hDlg
                            mciSendString "set MP3 time format milliseconds", "", 0, hDlg
                            mciSendString "status MP3 length", ReturnString, BYVAL 256, hDlg
                            MediaLength& = CLNG(VAL(ReturnString))
                            MediaLength& = MediaLength& \ 1000
                            FileTime$ = TRIM$(STR$(MediaLength& \ 60))
                            FileTime$ = FileTime$ + ":" + RIGHT$(TRIM$(STR$(100 + (MediaLength& MOD 60))), 2)
                            In order to know exactly how far along you are in an MP3 file playback, use the SetTimer command to start a timer (every tenth of a second should do) and then use the following code inside of a WM_TIMER handler in your callback function...
                            Code:
                            ' Start timer as soon as you issue the "play" command
                            SetTimer hDlg, 1, 100, BYVAL 0
                            
                            
                            ' In your callback function...
                            SELECT CASE CBMSG
                            CASE %WM_TIMER
                               IF MP3Playing& then
                                  mciSendString "set MP3 time format milliseconds", "", 0, hDlg
                                  mciSendString "status MP3 position", ReturnString, BYVAL 256, hDlg
                                  CurrMediaPos& = CLNG(VAL(ReturnString))
                                  CurrMediaPos& = CurrMediaPos& \ 1000
                                  Elapsed$ = TRIM$(STR$(CurrMediaPos& \ 60))
                                  Elapsed$ = Elapsed$ + ":" + RIGHT$(TRIM$(STR$(100 + (CurrMediaPos& MOD 60))),2)
                               END IF
                            To know when the MP3 playback is finished, you need to have an MM_MCINOTIFY handler in your callback function and include "notify" in your "play" command...
                            Code:
                            mciSendString "play MP3 notify", "", 0, hDlg
                            
                            
                            ' In your callback function...
                            SELECT CASE CBMSG
                            CASE %MM_MCINOTIFY
                               ' The Windows Media Control Interface has just sent a notification
                               SELECT CASE CBWPARAM
                               CASE %MCI_NOTIFY_SUCCESSFUL
                                  ' MP3 has finished playing successfully
                                  mciSendString "close MP3", "", 0, hDlg
                                  ' Remember to kill the timer used to track playback position
                                  KillTimer hDlg, 1
                               END SELECT
                            To set the volume of the MP3 playback, use the following command...
                            Code:
                            CurrVol& = 500 ' Anywhere from 0 to 1000 to increase/decrease volume
                            NewVolume$ = TRIM$(STR$(CurrVol&))
                            mciSendString "setaudio MP3 volume to " + NewVolume$, "", 0, hDlg

                            Hope these little tips help. If anyone needs specs on the MP3 Tag information inside an MP3 file (ID3v1 and ID3v2) just leave a message.

                            Timm

                            [This message has been edited by Timm Motl (edited September 27, 2000).]
                            mailto:[email protected]
                            Tsunami Record Manager

                            Comment


                            • #15
                              Errol...

                              You wrote...

                              "mciSendString seems to need a short path and filename"

                              In my experience, MCI will accept long paths and file names as long as there is an extra quotation mark at the beginning and end of the string. Accomplished like this...
                              Code:
                              MP3FileName$ = CHR$(34) + "C:\MY MUSIC\IF I HAD $1,000,000.MP3" + CHR$(34)
                              I would be interested to find out if it works for you, since you have a Win2K machine and I only have access to Win98 & Win98SE. Let me know. Thanks

                              Timm


                              ------------------
                              mailto:[email protected]
                              Tsunami Record Manager

                              Comment


                              • #16
                                Timm

                                Long filenames with double quotes do not work on either of my Windows boxes:
                                Pentium 450 MHz with Windows 2000 installed no service pack.
                                Pentium 133 MHz with Windows 95 version 4.00.1111 B with Media Player 6.2 installed.

                                Both Windows boxs play MP3's fine when using your code and calling GetShortPathName before using
                                mciSendString "open...."

                                Regards Errol

                                ------------------

                                Comment


                                • #17
                                  Errol...
                                  I'll have to run my code on some other PCs to see what's going on. I got my information from Microsoft's web site...

                                  *
                                  SYMPTOMS
                                  Multimedia API calls such as "mciSendString" may fail when you pass a file path or file name that uses long file names.
                                  *
                                  RESOLUTION
                                  Make sure you use a standard 8.3 path and file name -OR- wrap the path and file name in quotes.
                                  *
                                  STATUS
                                  This behavior is by design.
                                  *

                                  Could you make one more test for me? There are two ways to wrap a long file name in quotes... would you please try it both ways and let me know if it makes any difference?
                                  Code:
                                  MP3FileName$ = CHR$(34) + "C:\MY MUSIC\LONG MP3 FILE NAME.MP3" + CHR$(34)
                                  -OR-
                                  Code:
                                  MP3FileName$ = """C:\MY MUSIC\LONG MP3 FILE NAME.MP3"""  ' Notice 3 quotation marks
                                  Thanks for your time, Errol.

                                  Timm



                                  [This message has been edited by Timm Motl (edited September 27, 2000).]
                                  mailto:[email protected]
                                  Tsunami Record Manager

                                  Comment


                                  • #18
                                    Timm,

                                    Thanks a bunch...that's exactly what I needed.

                                    ------------------


                                    [This message has been edited by Ivan Iraola (edited September 28, 2000).]
                                    Ivan

                                    Uncle Droid (Android Apps)

                                    Comment


                                    • #19
                                      Timm

                                      I've tried the ways you indecated in your last post but they both
                                      failed to work on my Win2k box. The only way I could get your code
                                      to work with long file names, was by using the API call GetShortPathName().

                                      I Tried the following with no go
                                      MP3FileName = "D:\MP3S\Country\Red Sovine\Red Sovine- Bringing Mary Home.mp3"
                                      MP3FileName = """D:\MP3S\Country\Red Sovine\Red Sovine- Bringing Mary Home.mp3"""

                                      Sorry I could not be more helpfull.

                                      Regards Errol

                                      ------------------

                                      Comment


                                      • #20
                                        From what i have read myself it is better to always use the
                                        GetShortPathName API to convert names to 8.3 file format.

                                        ------------------
                                        Patrice Terrier
                                        mailto[email protected][email protected]</A>
                                        Patrice Terrier
                                        www.zapsolution.com
                                        www.objreader.com
                                        Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                                        Comment

                                        Working...
                                        X