Announcement

Collapse
No announcement yet.

Start MP3 recording from PBCC 5.2

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

  • Michael Mattias
    replied
    with Vista and Win7 in the multimedia functions. I'm still waiting for my boss to upgrade my clunky old WinXP system
    Um, there are some of us who not only don't consider Windows/XP to be "clunky and old", we did not even consider Vista an UP-Grade.

    I paid extra to "downgrade" my laptop from the bundled Vista to Windows/XP. Anyone need a paid-for Vista Home Premium license?

    Leave a comment:


  • tom kroto
    replied
    Paul's code worked for me

    Paul's code worked for me. I used mp3 song of about 43 seconds.
    Thanks Paul and Dave. I will study code for future use.

    Leave a comment:


  • Dave Biggs
    replied
    I was a bit surprised that the code I posted worked too - most of the sample MCI code I found on the forums used more elaborate setting up (but most wouldn't work for me anyway).
    It's very likely that there are differences introduced with Vista and Win7 in the multimedia functions. I'm still waiting for my boss to upgrade my clunky old WinXP system, so can't really help there.

    Paul's code works for me too (but only for .wav files ? - got to be my setup. Maybe Winamp competing with MediaPlayer or ITunes for MP3 )
    Last edited by Dave Biggs; 20 Nov 2009, 08:19 PM.

    Leave a comment:


  • Paul Dixon
    replied
    Tom,
    if you just want to play an mp3 file then the following works for me (Windows XP)

    Paul.
    Code:
    'PBCC5.02/PBWin9.02 program
    #INCLUDE "Win32api.inc"
    
    FUNCTION PBMAIN() AS LONG
    
    LOCAL ShortNameMP3 AS ASCIIZ * %MAX_PATH
    LOCAL FileToPlay AS ASCIIZ * %MAX_PATH
    LOCAL temp AS LONG
    
    FileToPlay = "C:\My music.mp3"    'change this to the file name of the mp3 file to play
    
    'mciSendString doesn't accept spaces in the name so convert to Short File names first
    GetShortPathName (FileToPlay,ShortNameMP3,SIZEOF(ShortNameMP3))
    
    'open the device
    temp=   mciSendString ("open " + $DQ + ShortNameMP3 + $DQ, "", %null,%null)
    checkmci(temp,"Can't Open mci")
    
    'play the track
    temp= mciSendString ("play " + $DQ + ShortNameMP3 + $DQ, "", %null,%null)
    checkmci(temp,"Can't play mci")
    
    IF temp <> 0 THEN EXIT FUNCTION
    
    SLEEP 10000   'play for about 10 seconds
    
    'stop the track
    temp= mciSendString ("stop " + $DQ + ShortNameMP3 + $DQ, "", %null,%null)
    CHECKmci(temp,"Can't stop mci")
    
    'close the device
    temp= mciSendString ("close " + $DQ + ShortNameMP3 + $DQ, "", %null,%null)
    CHECKmci(temp,"Can't close mci")
    
    END FUNCTION
    
    
    
    FUNCTION checkmci(var AS LONG, message AS STRING) AS LONG
            IF var <>0 THEN
                ? message +"Error="+HEX$(var)
                FUNCTION = 0
            ELSE
                FUNCTION = 1
            END IF
    END FUNCTION

    Leave a comment:


  • tom kroto
    replied
    did not work

    Dave,
    It did not work. I looked up mcisendstring and it says you have to issue open first to file.

    "You must start by sending the Open command before you can do anything else"

    I tried only .wav and used both the song.wav and notify.wav which I copied to current directory

    I am on windows 7?? if that makes a difference??
    Thanks for more ideas what do you think?

    Leave a comment:


  • Dave Biggs
    replied
    Tom, It's good that you were able to get Playsound to work though not with your song.
    I tried PlaySound with a (Audacity) converted MP3 music file (~49,000KB) and it played OK.
    But according to the SDK docs, 'Size does matter'
    The sndPlaySound and PlaySound functions load an entire waveform-audio file into memory and, in effect, limit the size of the file they can play.
    Use sndPlaySound and PlaySound to play waveform-audio files that are small — up to about 100K.
    These two functions also require the sound data to be in a format that is playable by one of the installed waveform-audio drivers, including the wave mapper.

    For larger sound files, use the Media Control Interface (MCI) services.
    Here's an example of using MCI which worked on my PC..
    Code:
    #INCLUDE "WIN32API.INC"
     
    FUNCTION PBMAIN()
     LOCAL szFile AS ASCIIZ * %MAX_PATH
     LOCAL szAlias AS ASCIIZ * %MAX_PATH
     ' Set the file name...
      szFile = CURDIR$ + "\BBoys.wav"   'your file here
     
    ' Start playing the file...
      mciSendString "play " + szFile, BYVAL %NULL, 0, BYVAL %NULL
      ? szFile
      ? "Playing... Spacebar to stop"
      WAITKEY$
     
    ' Close the file...
      mciSendString "close " + szFile, BYVAL %NULL, 0, BYVAL %NULL
     
      ? "Spacebar to end"
      WAITKEY$
     
    END FUNCTION
    '------------------/

    Leave a comment:


  • tom kroto
    replied
    different kinds of .wav

    I got playsound to work both with a path and using system defaults like RingIn for fax. My original .wav was an actual song and it did not work with playsound (except for clicking tones repeated). Using "ringIn" or notify.wav worked. So my .wav song was either a different kind of .wav or too long for this API?

    I got a solution, but I still wonder why my .wav song would not work.

    Leave a comment:


  • Jerry Fielden
    replied
    4 charecter extentions. New to me.

    I give it a try but mcisendstring wouldn't open one for me.

    How is that done with mcisendstring?

    Leave a comment:


  • Michael Mattias
    replied
    >FileType$ = MID$(TRIM$(MediaFile$),-3,3)

    There's a handy little new function in 5x/9x for busting up file names.....

    FileType$ = LTRIM$(PATHSCAN$(EXTN, MediaFIle$), "." )

    (Why the "." is included when asking for EXTN is a mystery to me. Oh, well.)

    BTW, you are assuming an exactly 3-character file extension. If we start getting "wavx" and "mp3x" like we now get "xlsx" with newer Excel spreadsheets you could have one of those hard-to-find bugs here!

    Leave a comment:


  • Jerry Fielden
    replied
    If you can't get Playsound to work, maybe you could try mcisendstring.
    Here's one, I don't know who wrote it, but I've use something simular in PBCC many times, in regular and windows SDK style.

    I haven't tried it but it looks like to me it would work with Wav, Midi & MP3. Make sure you enter full path, even if its in the same directory. Like drive letter and all. If I remember right, I think thats required.





    Code:
     #INCLUDE "\bin\win32api\w32api\WIN32API.INC"
     FUNCTION PBMAIN
     LOCAL ReturnString AS ASCIIZ * 256
    
       LINE INPUT " Enter Sound file with extention  "; MediaFile$
       MediaFile$ = CURDIR$ + "\" + MediaFile$
       FileType$ =  MID$(TRIM$(MediaFile$),-3,3)
       MciSendString "open " + MediaFile$ + " alias " + FileType$, "", 0, 0
       MciSendString "set " + FileType$ + " time format milliseconds", "", 0, 0
       MciSendString "status " + FileType$ + " length", ReturnString, BYVAL 256, 0
       MediaLength& = CLNG(VAL(ReturnString))
       MciSendString "play  " + FileType$ , "", %NULL, 0
    
       FOR x& = 1 TO MediaLength& / 100
           HitAkey$ = INKEY$                   'Hit any key to exit most,
           IF HitAkey$ <> "" THEN EXIT FOR     'except AVIs
           SLEEP 100
       NEXT x&
    
       MciSendString "stop " + FileType$ , "", 0, 0
       MciSendString "close " + FileType$ ,"", 0, 0
    
     END FUNCTION

    Leave a comment:


  • tom kroto
    replied
    thank you

    I printed all references you gave me. Thnak you very much. I will research.

    Leave a comment:


  • Dave Biggs
    replied
    There are numerous examples of how to use ShellExecute on the forums. It's described here http://msdn.microsoft.com/en-us/libr...53(VS.85).aspx Closing the application that it has launched to play the media file is a bit more involved (which is another reason to use PlaySound )

    btw try this?
    Code:
    SndPlaySound "SystemStart", %SND_ASYNC OR %SND_LOOP
    PlaySound is part of the Windows API http://en.wikipedia.org/wiki/Windows_api (accessible to but not particularly part of VB).

    How to learn the API? Well hanging around these forums for a while is one way, another is by Browsing the contents of the Windows 32-bit API help file: http://www.powerbasic.com/files/pub/mstools/Win32.zip

    There are a few books that have been recommended here over time. I have a copy of Windows 2000 programming from the ground up By Herbert Schildt which is pretty good - others are listed here http://www.powerbasic.com/support/pb...hread.php?t=39

    Re: Code tags:
    The vBulletin bulletin board software allows the use of code tags to format messages in various ways including the [code] tags which switch to a fixed-width (monospace) font and preserve all spacing.
    http://www.powerbasic.com/support/pb....php?do=bbcode

    Leave a comment:


  • Michael Mattias
    replied
    Tell me more about ShellExecute, particularly how do I go about stopping mp3 once it starts
    If you use SHELL or ShellExecute you can't stop it. Using those functions, you give up control of the playing to the launched program.

    Read the doc for the first parameter (pszSound) of the Playsound function. That which you seek you will there find.

    MCM

    Leave a comment:


  • tom kroto
    replied
    OK some progress

    Dave, Thanks for replies. Tell me more about ShellExecute, particularly how do I go about stopping mp3 once it starts. I see from internet that it is API. I have some VB but I have always wondered how people know about these API's. It looks like such a jungle to find anything in VB.

    As for playsound the internet says it is vb6 API. I have vb.net framework on my XP laptop. Maybe that is why it didn't work???? Forgive my ignorance. I appreciate the help.

    last stupid question: in this forum how do you create code insert block? I know how to copy the code only, but I can't figure out how to create a code block. Thanks

    Leave a comment:


  • Dave Biggs
    replied
    Hmm, Clicks are something

    Did you try with other system .WAVs like TADA.WAV or RINGIN.WAV (Windows/Media folder on my WinXP box)?

    PlaySound has been around since Win95 (Winmm.lib I think) so should be on your system too.

    Another option?
    Code:
    SHELLEXECUTE %NULL, "open", "Some.mp3", "", "", %SW_HIDE 'SHOWNORMAL

    Leave a comment:


  • tom kroto
    replied
    just get a clicking tone

    I tried several ideas but the most I got was a clicking tone repeating. Maybe I don't have dll to do the job?
    here is code I used
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "WIN32API.INC"
    FUNCTION PBMAIN()

    PlaySound "C:\Users\tom kroto\Documents\My Recordings\calvary.wav", 0, %SND_ASYNC OR %SND_LOOP ' delete OR %SND_LOOP to just play once
    ' ^^^^^^^^^^ your .wav here
    ' could be a .wav file in current dir or path or elsewhere (enter full pathname).
    PRINT "any key to end"
    WAITKEY$
    PlaySound "", 0, %SND_ASYNC ' stop the loop

    END FUNCTION
    '------------------/PBMain
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    How about sample COM for media player??? anybody?

    Leave a comment:


  • Michael Mattias
    replied
    Never tried it, but Windows' Media Player offers a COM interface. I think WMP plays just about any format.

    Leave a comment:


  • Dave Biggs
    replied
    If you were to Export your .MP3 file as .WAV from within Audacity..
    The API function 'PlaySound' is pretty easy to use:
    Code:
    #INCLUDE "WIN32API.INC"
    FUNCTION PBMAIN()
     
      PlaySound "chimes.wav", 0, %SND_ASYNC OR %SND_LOOP      ' delete OR %SND_LOOP to just play once
        '        ^^^^^^^^^^ your .wav here
        ' could be a .wav file in current dir or path or elsewhere (enter full pathname).
      PRINT "any key to end"
      WAITKEY$
      PlaySound "", 0, %SND_ASYNC                             ' stop the loop
     
    END FUNCTION
    '------------------/PBMain
    Last edited by Dave Biggs; 17 Nov 2009, 10:09 AM. Reason: Remove reference to PBWin file

    Leave a comment:


  • tom kroto
    started a topic Start MP3 recording from PBCC 5.2

    Start MP3 recording from PBCC 5.2

    I would like to start an MP3 recording from within a pbcc5.2 program. I had this idea of making a recording through audacity and playing it if a specific error is reached within the program.

    Crazy idea? Can't be done. Sample code. Thank you.
Working...
X