#include <Bass.au3> #include <BassConstants.au3> ;Open Bass.DLL $bass_dll = DllOpen("bass.dll") Global $S_DOWNLOAD = False; Download = True, Just Play = False Global $o_file = @DesktopDir & "\download.mp3"; Download Location Global $FILEHANDLE Global $STREAMISDOWNLOADING = 0 ;Open Bass.DLL $bass_dll = DllOpen("bass.dll") ;Init Bass.DLL functions _BASS_Init($bass_dll, 0, -1, 44100, 0, "") If @error Then MsgBox(0, "Error", 'Error initializing audio!' & @LF & "@ERROR = " & @error); Exit EndIf $URL = "<a href='http://www.djchuckb.com/Rihanna_-_iTunes_-_01_-_Disturbia.mp3' class='bbc_url' title='External link' rel='nofollow external'>http://www.djchuckb.com/Rihanna_-_iTunes_-_01_-_Disturbia.mp3"</a> $music_handle = _BASS_StreamCreateURL($bass_dll, $URL, 0, $BASS_SAMPLE_FLOAT, "TestFunc") $error_e = @error ;Check error with dllcall. If Not @error Then _BASS_ChannelPlay($bass_dll, $music_handle, 1) While $STREAMISDOWNLOADING Sleep(100) WEnd While 1 $state = _BASS_ChannelIsActive($bass_dll, $music_handle) If $state = 0 Then Sleep(200) $ret = _BASS_ChannelUpdate($bass_dll, $music_handle, 0) If $ret = 0 Then ExitLoop EndIf Sleep(200) WEnd Else GetRadioError($error_e) EndIf Func GetRadioError($ecode) $emsg = "" Switch $ecode Case 0 $emsg = "everything is A-OKAY" Case 8 $emsg = "BASS_ERROR_INIT BASS_Init has not been successfully called." Case 37 $emsg = "BASS_ERROR_NOTAVAIL Only decoding channels (BASS_STREAM_DECODE) are allowed when using the " & _ "'no sound' device. The BASS_STREAM_AUTOFREE flag is also unavailable to decoding channels." Case 32 $emsg = "BASS_ERROR_NONET No internet connection could be opened. Can be caused by a bad proxy setting." Case 20 $emsg = "BASS_ERROR_ILLPARAM url is not a valid URL." Case 40 $emsg = "BASS_ERROR_TIMEOUT The server did not respond to the request within the timeout period, as set with the BASS_CONFIG_NET_TIMEOUT config option." Case 2 $emsg = "BASS_ERROR_FILEOPEN The file could not be opened." Case 41 $emsg = "BASS_ERROR_FILEFORM The file's format is not recognised/supported." Case 44 $emsg = "BASS_ERROR_CODEC The file uses a codec that's not available/supported. This can apply" & _ "to WAV and AIFF files, and also MP3 files when using the 'MP3-free' BASS version." Case 6 $emsg = "BASS_ERROR_FORMAT The sample format is not supported by the device/drivers. " & _ "If the stream is more than stereo or the BASS_SAMPLE_FLOAT flag is used, it could be that they are not supported." Case 42 $emsg = "BASS_ERROR_SPEAKER The specified SPEAKER flags are invalid. The device/drivers do not support them, they are" & _ "attempting to assign a stereo stream to a mono speaker or 3D functionality is enabled." Case 1 $emsg = "BASS_ERROR_MEM There is insufficient memory." Case 21 $emsg = "BASS_ERROR_NO3D Could not initialize 3D support." Case - 1 $emsg = "BASS_ERROR_UNKNOWN Some other mystery problem!" EndSwitch MsgBox(0, "Error Message", $emsg) EndFunc ;==>GetRadioError Func TestFunc($buffer, $length, $user) If Not $S_DOWNLOAD Then $STREAMISDOWNLOADING = 1 If Not $buffer Then $STREAMISDOWNLOADING = 0 EndIf Else $STREAMISDOWNLOADING = 1 If Not $FILEHANDLE Then $FILEHANDLE = FileOpen($o_file, 18) If Not $buffer Then $STREAMISDOWNLOADING = 0 FileClose($FILEHANDLE) $FILEHANDLE = 0 Else DllStructCreate("byte[" & $length & "]", $buffer) FileWrite($FILEHANDLE, DllStructGetData(DllStructCreate("byte[" & $length & "]", $buffer), 1)) EndIf EndIf EndFunc ;==>TestFunc Func OnAutoItExit () _Bass_StreamFree ($bass_dll, $music_handle) _Bass_Free($bass_dll) EndFunc
Thanks for any help, I greatly appreciate it.
Cheers,
Brett
Edited by BrettF, 13 November 2008 - 10:53 PM.




