AdmiralAlkex Posted May 20, 2010 Share Posted May 20, 2010 (edited) Last night I felt like creating a simple cd-player. Here's the result:expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- Bones CD-Player v5 AutoIt Version: 3.3.6.1 Author: Alexander Samuelsson (AdmiralAlkex) Script Function: A simple CD-Player. Name is a tribute to: Temperance "Bones" Brennan AND Leonard H. "Bones" McCoy. #ce ---------------------------------------------------------------------------- #Include "SDL.au3" Global $pCD, $iOldCurrent Global $sLongStruct = "int id;int status;int numtracks;int cur_track;int cur_frame" For $iX = 0 To $_SDL_MAX_TRACKS $sLongStruct &= ";byte id;byte type;ushort unused;uint length;uint offset" Next OnAutoItExitRegister("_OnExit") _SDL_Init($_SDL_INIT_CDROM) $pCD = _SDL_CDOpen(0) If $pCD = 0 Then Exit _SDL_CDStatus($pCD) HotKeySet("{MEDIA_NEXT}", "_Next") HotKeySet("{MEDIA_PREV}", "_Prev") HotKeySet("{MEDIA_STOP}", "_Stop") HotKeySet("{MEDIA_PLAY_PAUSE}", "_PlayPause") _SDL_CDPlayTracks($pCD, 0, 0, 0, 0) AdlibRegister("_Status") While 1 Sleep(100) WEnd Func _Status() ;Jumps to first song if disc ended. _SDL_CDStatus($pCD) $pTemp = DllStructCreate($sLongStruct, $pCD) $iMax = DllStructGetData($pTemp, "numtracks") $iCurrent = DllStructGetData($pTemp, "cur_track") If $iCurrent <> $iMax -1 Then Return $iCurrentF = DllStructGetData($pTemp, "cur_frame") $iStatus = DllStructGetData($pTemp, "status") $iLength = DllStructGetData($pTemp, 6+ ($iMax -1) * 5 +3) ;Black magic here. If $iCurrentF > $iLength -$_SDL_CD_FPS And $iCurrentF = $iOldCurrent Then _Next() ;More black magic (not sure if this is necessary) $iOldCurrent = $iCurrentF EndFunc Func _Next() _SDL_CDStatus($pCD) $pStruct = DllStructCreate($sLongStruct, $pCD) $iMax = DllStructGetData($pStruct, "numtracks") $iCurrent = DllStructGetData($pStruct, "cur_track") $iCurrent += 1 If $iCurrent = $iMax Then $iCurrent = 0 _SDL_CDPlayTracks($pCD, $iCurrent, 0, 0, 0) EndFunc Func _Prev() _SDL_CDStatus($pCD) $pStruct = DllStructCreate($sLongStruct, $pCD) $iMax = DllStructGetData($pStruct, "numtracks") $iCurrent = DllStructGetData($pStruct, "cur_track") $iCurrentF = DllStructGetData($pStruct, "cur_frame") Local $iMinutes, $iSeconds, $Frames _SDL_FRAMES_TO_MSF($iCurrentF, $iMinutes, $iSeconds, $Frames) If $iMinutes *60 +$iSeconds > 5 Then _SDL_CDPlayTracks($pCD, $iCurrent, 0, 0, 0) Else $iCurrent -= 1 If $iCurrent = -1 Then $iCurrent = $iMax -1 _SDL_CDPlayTracks($pCD, $iCurrent, 0, 0, 0) EndIf EndFunc Func _Stop() If _SDL_CDStatus($pCD) = $_SDL_CD_STOPPED Then _SDL_CDEject($pCD) Else _SDL_CDStop($pCD) EndIf EndFunc Func _PlayPause() Switch _SDL_CDStatus($pCD) Case $_SDL_CD_TRAYEMPTY _SDL_CDEject($pCD) Case $_SDL_CD_PAUSED _SDL_CDResume($pCD) Case $_SDL_CD_PLAYING _SDL_CDPause($pCD) Case $_SDL_CD_STOPPED _SDL_CDPlayTracks($pCD, 0, 0, 0, 0) EndSwitch EndFunc Func _OnExit() If $pCD <> 0 Then _SDL_CDClose($pCD) If $__SDL_DLL <> -1 Then _SDL_Quit() EndFuncYou need SDL.au3 and SDL.dll from theSDL UDF to run it. Edited May 21, 2010 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
trancexx Posted May 21, 2010 Share Posted May 21, 2010 It's kinda cool. You need to correct structures for it to work. (This means no one tried? Even cooler) Why does it continue to play after I kill my AutoIt? ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 21, 2010 Author Share Posted May 21, 2010 (edited) It's kinda cool.You need to correct structures for it to work. (This means no one tried? Even cooler)Why does it continue to play after I kill my AutoIt?Errr... I assume you mean line 64 and 75? They aren't really incorrect (my copy of sdl.au3 is a little bit different from yours ), I just forgot to change them to $sLongStruct (first post updated).It continues to play because.... I don't remember. I had another script doing that a long time ago, but I can't get it to happen now.You aren't executing _SDL_CDClose()? Please try a graceful exit (like exiting by the tray menu).Also, what Windows and AutoIt do you have? (I want to replicate the error) Include service packs, @OSArch, everything. Edited May 21, 2010 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
trancexx Posted May 21, 2010 Share Posted May 21, 2010 Errr... I assume you mean line 64 and 75? They aren't really incorrect (my copy of sdl.au3 is a little bit different from yours ), I just forgot to change them to $sLongStruct (first post updated).Yes, I was unclear on purpose. It continues to play because.... I don't remember. I had another script doing that a long time ago, but I can't get it to happen now.You aren't executing _SDL_CDClose()? Please try a graceful exit (like exiting by the tray menu).Also, what Windows and AutoIt do you have? (I want to replicate the error) Include service packs, @OSArch, everything.On XP SP3 it continues playing. On Win7 it stops as expected.I said kill. Otherwise fine. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 21, 2010 Author Share Posted May 21, 2010 (edited) Then I fail to see what the question is about. Are you asking me where in the sdl source-code something goes wrong? I'm not sure I can answer that. Since XP behaves differently how do we know it isn't just a bug in XP? Edit1: I looked in the source and SDL uses MCI. Edit2: The device is opened with MCI_OPEN_SHAREABLE, does that mean anything? I don't know. Edited May 21, 2010 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
trancexx Posted May 21, 2010 Share Posted May 21, 2010 Then I fail to see what the question is about.Is it you? That's what was it about.- I don't know, it shouldn't be me, I'm doing everything as I'm suppose to. would have been enough. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 22, 2010 Author Share Posted May 22, 2010 Is it you? That's what was it about.- I don't know, it shouldn't be me, I'm doing everything as I'm suppose to. would have been enough.Errr right. So while we are having this totally weird conversation, do you think there's anything I can do about this? Except recommending everyone to ditch WinXP .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now