You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
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.
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
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
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
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
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.
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
(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!
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.
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
'------------------/
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
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 )
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment