Last active
April 21, 2019 14:36
-
-
Save SunShineSilver-mdA/cd9fb004d8a98d56096ebd81621dcf76 to your computer and use it in GitHub Desktop.
SunShineSilver.mdA MP3 Player.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[######################################################]]-- | |
--[[########### SunShineSilver.mdA MP3 Player ############]]-- | |
--[[ ::START:: SunShineSilver.mdA Lua Script ]]-- | |
--[[Compare Tables]]function TCOMP(T,C,...) for K,V in pairs(C) do T[K]=V end if select('#',...)>0 then return TCOMP(T,...) else return T end end | |
--[[FIRST_LOAD=nil;]] | |
function assSunShineSilverMP3Player() | |
--[[-> https://i.imgur.com/I2qRt5v.png https://i.imgur.com/FFnURJQ.png | |
######################################################################################################### | |
----------------------------------------------------------------> | |
################ | |
[ Requirements ]: | |
Header: Mmsystem.h (include Windows.h) | |
Library: Winmm.lib | |
DLL: Winmm.dll | |
----------------------------------------------------------------> | |
################# | |
[ MCI Functions ]: | |
mciExecute | |
mciGetCreatorTask | |
mciGetDeviceID | |
mciGetDeviceIDFromElementID | |
1->mciGetErrorString | |
mciGetYieldProc | |
2->mciSendCommand | |
3-> mciSendString | |
mciSetYieldProc | |
----------------------------------------------------------------> | |
############################## | |
[ mciGetErrorString function ] | |
BOOL mciGetErrorString(DWORD fdwError,LPTSTR lpszErrorText,UINT cchErrorText); | |
fdwError: Error code returned by the mciSendCommand or mciSendString function. | |
lpszErrorText: Pointer to a buffer that receives a null-terminated string describing the specified error. | |
cchErrorText: Length of the buffer, in characters, pointed to by the lpszErrorText parameter. | |
-> Returns TRUE if successful or FALSE if the error code is not known. | |
MCIERROR mciSendCommand & 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 return values, pass the return value to the mciGetErrorString function. | |
----------------------------------------------------------------> | |
############################## | |
[ mciSendCommand function ] | |
2-> MCIERROR mciSendCommand(MCIDEVICEID IDDevice, UINT uMsg, DWORD_PTR fdwCommand, DWORD_PTR dwParam); | |
IDDevice: Device identifier of the MCI device that is to receive the command message. | |
This parameter is not used with the MCI_OPEN command message. | |
uMsg: Command message. For a list, see Multimedia Commands. | |
fdwCommand: Flags for the command message. | |
dwParam: Pointer to a structure that contains parameters for the command message. | |
----------------------------------------------------------------> | |
########################## | |
[ mciSendString function ] | |
3-> MCIERROR mciSendString(LPCTSTR lpszCommand, LPTSTR lpszReturnString, UINT cchReturn, HANDLE hwndCallback); | |
lpszCommand: Pointer to a null-terminated string that specifies an MCI command string. | |
For a list, see Multimedia Command Strings. | |
lpszReturnString: Pointer to a buffer that receives return information. | |
If no return information is needed, this parameter can be NULL. | |
cchReturn: Size, in characters, of the return buffer specified by the lpszReturnString parameter. | |
hwndCallback: Handle to a callback window if the "notify" flag was specified in the command string. | |
----------------------------------------------------------------> | |
####################### | |
[ MCI Command Strings ]: | |
"break","capability","capture","close", | |
"configure","copy","cue","cut","delete", | |
"escape","freeze","index","info","list", | |
"load","mark","monitor","open","paste", | |
"pause","play","put","quality","realize", | |
"record","reserve","restore","resume","save", | |
"seek","set","setaudio","settimecode", | |
"settuner","setvideo","signal","spin", | |
"status","step","stop","sysinfo","undo", | |
"unfreeze","update","where","window", | |
----------------------------------------------------------------> | |
#MediaFile: | |
function fcSendCommand(Command) | |
writeStringLocal(msPlayerCommand.Memory , Command) | |
writeBytesLocal (msPlayerCommand.Memory+#Command , 0); | |
executeCodeLocal('SunShineSilverMP3Player',msPlayerCommand.Memory); | |
return readStringLocal(msPlayerCommand.Memory+1024,100); | |
end | |
----------------------------------------------------------------> | |
fcSendCommand(string.format('open "%s" type mpegvideo alias MediaFile',FilePath)) | |
function(lpszCommand,TEXT("open %s %s %s"),lpszDevice,lpszOpenFlags,lpszFlags); | |
----------------------------------------------------------------> | |
-> setaudio -> volume to | |
function(lpszCommand,TEXT("setaudio %s %s %s"),lpszDeviceID,lpszAudio,lpszFlags); | |
volume to factor: | |
Sets the average audio volume for both audio channels. | |
If the left and right volumes have been set to different values, | |
then the ratio of left-to-right volume is approximately unchanged. | |
-> play | |
function(lpszCommand,TEXT("play %s %s %s"),lpszDeviceID,lpszPlayFlags,lpszFlags); | |
-> stop | |
function(lpszCommand, TEXT("stop %s %s %s"),lpszDeviceID,lpszStopFlags,lpszFlags); | |
-> resume | |
function(lpszCommand, TEXT("resume %s %s"),lpszDeviceID,lpszFlags); | |
-> pause | |
function(lpszCommand,TEXT("pause %s %s"),lpszDeviceID,lpszFlags); | |
-> close | |
function(lpszCommand, TEXT("close %s %s"),lpszDeviceID,lpszFlags); | |
#########################################################################################################]]-- | |
if assSunShineSilverMP3Player_Loaded then return true end | |
if autoAssemble([[loadlibrary(winmm.dll) | |
alloc(SunShineSilverMP3Player,4096) | |
registersymbol(SunShineSilverMP3Player) | |
SunShineSilverMP3Player: | |
lea rsp,[rsp-28] | |
lea rsi,[rcx+400] | |
mov rdx,0 | |
mov r8,0 | |
mov r9,0 | |
call mciSendStringA | |
mov rcx,rax | |
mov rdx,rsi | |
mov r8,400 | |
call mciGetErrorStringA | |
lea rsp,[rsp+28] | |
ret]],true) | |
then assSunShineSilverMP3Player_Loaded=true; | |
msPlayerCommand=createMemoryStream(); | |
msPlayerCommand.Size=2048; | |
return true; else return false; end | |
end | |
function fcSendCommand(Command) | |
writeStringLocal(msPlayerCommand.Memory, Command); | |
writeBytesLocal (msPlayerCommand.Memory+#Command, 0); | |
executeCodeLocal('SunShineSilverMP3Player',msPlayerCommand.Memory); | |
return readStringLocal(msPlayerCommand.Memory+1024,100); | |
end | |
function fcPlay(FilePath) | |
if not assSunShineSilverMP3Player() then return end | |
local start_a,start_b,cut_a,cut_b,space,str_end=0,0,0,"","",""; | |
if FilePath~=nil then | |
---> Input FilePath='C:\\Users\\mdA\\Desktop\\The Boy Rackers - Bla Bla Bla(Original Mix).mp3' | |
local str_len=string.len(FilePath); | |
for i=0,str_len,1 do--[[--> FilePath(...)removing paths]] | |
start_a,start_b=string.find(FilePath, "\\", i, str_len); | |
if start_b~=nil then | |
str_end=string.sub(FilePath, start_b+1, str_len-4); | |
end | |
end--[[--> Output str_end='The Boy Rackers - Bla Bla Bla(Original Mix)']] | |
if string.len(str_end)>42 then--[[-->str_end(...)check length, | |
if need then substring the last space from the max length]] | |
space=string.find(str_end, " ", 30, str_len); | |
cut_a=string.sub(str_end, 0, space); | |
cut_b=string.sub(str_end, space+1, str_len); | |
str_end=cut_a..'\n'..cut_b; | |
end--[[--> if true then | |
Output --> str_end in 2 lines | |
'The Boy Rackers - Bla Bla Bla | |
(Original Mix)' | |
#setlabel#end]] | |
--[[ Edit: -> TCOMP(... | |
CEMP3Label.Caption=str_end | |
CEMP3Label.Transparent=true | |
CEMP3Label.Top=37 | |
CEMP3Label.Left=13 | |
CEMP3Label.bringToFront()]] | |
TCOMP(CEMP3Label,{Top=37,Left=13,Caption=tostring(str_end),Transparent=true,bringToFront}); | |
TCOMP(LBF1,{Size=9,Height=-12,Color=0xE63C98,Name='Consolas',Style='[fsBold]',Pitch='fpFixed'}); | |
PopUpMessage(string.format('SunShineSilver.mdA MP3 Player v1.0a\n\nMP3 File:\n\n'..str_end..'\n'),2400) | |
else | |
--[[CEMP3Label.Caption="None MP3 File Loaded!"; | |
CEMP3Label.bringToFront() | |
CEMP3Label.Top=37 | |
CEMP3Label.Left=13 | |
CEMP3Label.Transparent=true]] | |
TCOMP(CEMP3Label,{Top=37,Left=13,Caption="None MP3 File Loaded!\nTo Load a MP3, Drag-And-Drop a File in",Transparent=true,bringToFront}); | |
TCOMP(LBF1,{Size=9,Height=-12,Color=0xE63C98,Name='Consolas',Style='[fsBold]',Pitch='fpFixed'}); | |
PopUpMessage(string.format('SunShineSilver.mdA MP3 Player v1.0a\n\nMP3 File:\n\n'..str_end..'\n'),2400) | |
end | |
fcSendCommand('close MediaFile'); | |
fcSendCommand(string.format('open "%s" type mpegvideo alias MediaFile',FilePath)) | |
fcSendCommand('play MediaFile'); | |
end | |
function fcPause() | |
if not assSunShineSilverMP3Player() then return end | |
if not MP3PlayerPaused then fcSendCommand('pause MediaFile');MP3PlayerPaused=true; | |
else fcSendCommand('resume MediaFile');MP3PlayerPaused=false;end | |
end | |
function fcStop() if not assSunShineSilverMP3Player() then return end;fcSendCommand('stop MediaFile');end; | |
function fcVolume(volume) if not assSunShineSilverMP3Player() then return end;fcSendCommand('setaudio MediaFile volume to '..volume);end; | |
--[[ | |
local smFileName,smFilePath='',''; | |
smFileName=findTableFile('Danceboy_Spinnin.mp3').Stream; | |
smFilePath=TrainerOrigin or getMainForm().OpenDialog1.InitialDir | |
smFilePath=smFilePath..'Danceboy_Spinnin.mp3'; | |
FileCheck=io.open(smFilePath); | |
if FileCheck==nil then | |
smFileName.saveToFile(smFilePath); | |
--print('File Does Not Exist!',smFilePath,smFileName); | |
else | |
--print('File Already Exist!\n'..smFilePath..'\nStream '..tostring(smFileName),smFilePath); | |
end | |
]] | |
function CEPlayClick(sender)fcPlay(FilePath); fcVolume(CEVolumeFade.Position*10);end; | |
function CEPauseClick(sender) fcPause();end; | |
function CEStopClick(sender) fcStop();end; | |
function CEVolumeChange(sender) fcVolume(CEVolumeFade.Position*10);end; | |
function CECloseClick() closeCE();return caFree;end; | |
function CreateBackground() | |
local IMG=createImage(mdA) | |
IMG.align=alClient | |
local NET=getInternet() | |
local BG=NET.getURL("https://i.imgur.com//hvqbRgT.png") | |
NET.destroy() | |
local SS=createStringStream(BG) | |
IMG.Picture.LoadFromStream(SS) | |
SS.destroy() | |
IMG.transparent=false --IMG.stretch=true | |
IMG.sendToBack() | |
end | |
function PopUpMessage(Text,Time) | |
--################################# | |
local PopUpForm=createForm(false); | |
TCOMP(PopUpForm,{Width=mdA.Width+15,Height=mdA.Height+35,Top=mdA.Top-5,Left=mdA.Left-4, | |
BorderStyle='bsNone',FormStyle='fsStayOnTop',Color='clBlack'}); | |
--################################# | |
local PopUpLabel1=createLabel(PopUpForm); | |
TCOMP(PopUpLabel1,{Top=6,Left=6,Caption=Text,Color=0x000000}); | |
local PF1=PopUpLabel1.Font;PopUpLabel1.BorderSpacing.Around=20; | |
TCOMP(PF1,{Color=0xE63C98,Size=11,Height=-15,CharSet=1252,Name='Consolas',Style='[fsBold]',Pitch='fpFixed'}); | |
--################################# | |
local PopUp=createTimer(PopUpForm); | |
PopUp.Interval=Time; | |
PopUp.OnTimer=function() PopUpForm.destroy();end | |
if FIRST_LOAD==nil then mdA.hide();PopUpForm.hide(); | |
else PopUpForm.show();end | |
end | |
function MP3Player_UI() | |
--################################# | |
--> ::START:: | |
---> Form | |
--[[ Edit: -> TCOMP(... Compare Tables goto NewForm | |
mdA=createForm(true) | |
mdA.Caption='SunShineSilver.mdA MP3 Player v1.0a' | |
mdA.Position='poScreenCenter' | |
mdA.Width=305 | |
mdA.Height=120 | |
mdA.Visible=true | |
mdA.Color='clBlack' | |
mdA.BorderStyle='bsToolWindow' | |
mdA.BorderIcons='[biSystemMenu,biMinimize]' | |
mdA.PopupMode='pmAuto' | |
mdA.ShowInTaskBar='stAlways' | |
mdA.Align=alNone | |
mdA.Enabled=nil | |
mdA.Visible=true | |
mdA.AllowDropFiles=true | |
mdA.OnClose=CECloseClick | |
]] | |
--::NewForm::-- | |
mdA=createForm(true) | |
TCOMP(mdA,{Caption='SunShineSilver.mdA MP3 Player v1.0a',Position='poScreenCenter', | |
Width=305,Height=120,Visible=true,Color='clBlack',PopupMode='pmAuto', | |
BorderStyle='bsToolWindow',BorderIcons='[biSystemMenu,biMinimize]',ShowInTaskBar='stAlways', | |
Align=alNone,Enabled=true,Visible=true,AllowDropFiles=true--[[,OnClose=CECloseClick]]}); | |
CreateBackground() | |
--################################# | |
-----> Controls | |
---> CEPlayButton | |
--[[ Edit: -> TCOMP(... | |
CEPlayButton=createButton(mdA) | |
CEPlayButton.Caption='Play' | |
CEPlayButton.Left=10 | |
CEPlayButton.Top=68 | |
CEPlayButton.Width=40 | |
CEPlayButton.Height=23 | |
CEPlayButton.Align=alNone | |
CEPlayButton.Enabled=true | |
CEPlayButton.Visible=true | |
CEPlayButton.BidiMode=bdLeftToRight | |
CEPlayButton.TabOrder=0 | |
CEPlayButton.TabStop=true | |
CEPlayButton.OnClick=CEPlayClick | |
]] | |
CEPlayButton=createButton(mdA) | |
TCOMP(CEPlayButton,{Caption='Play',Left=10,Top=68,Width=40,Height=23,TabOrder=0,TabStop=true, | |
Align=alNone,Enabled=true,Visible=true,BidiMode=bdLeftToRight,OnClick=CEPlayClick}); | |
--################################# | |
---> CEPauseButton | |
--[[ Edit: -> TCOMP(... | |
CEPauseButton=createButton(mdA) | |
CEPauseButton.Caption='Pause' | |
CEPauseButton.Left=50 | |
CEPauseButton.Top=68 | |
CEPauseButton.Width=40 | |
CEPauseButton.Height=23 | |
CEPauseButton.Align=alNone | |
CEPauseButton.Enabled=true | |
CEPauseButton.Visible=true | |
CEPauseButton.BidiMode=bdLeftToRight | |
CEPauseButton.TabOrder=1 | |
CEPauseButton.TabStop=true | |
CEPauseButton.OnClick=CEPauseClick | |
]] | |
CEPauseButton=createButton(mdA) | |
TCOMP(CEPauseButton,{Caption='Pause',Left=50,Top=68,Width=40,Height=23,TabOrder=1,TabStop=true, | |
Align=alNone,Enabled=true,Visible=true,BidiMode=bdLeftToRight,OnClick=CEPauseClick}); | |
--################################# | |
---> CEStopButton | |
--[[ Edit: -> TCOMP(... | |
CEStopButton=createButton(mdA) | |
CEStopButton.Caption='Stop' | |
CEStopButton.Left=90 | |
CEStopButton.Top=68 | |
CEStopButton.Width=40 | |
CEStopButton.Height=23 | |
CEStopButton.Align=alNone | |
CEStopButton.Enabled=true | |
CEStopButton.Visible=true | |
CEStopButton.BidiMode=bdLeftToRight | |
CEStopButton.TabOrder=2 | |
CEStopButton.TabStop=true | |
CEStopButton.OnClick=CEStopClick | |
]] | |
CEStopButton=createButton(mdA) | |
TCOMP(CEStopButton,{Caption='Stop',Left=90,Top=68,Width=40,Height=23,TabOrder=2,TabStop=true, | |
Align=alNone,Enabled=true,Visible=true,BidiMode=bdLeftToRight,OnClick=CEStopClick}); | |
--################################# | |
---> CEVolumeFade | |
--[[ Edit: -> TCOMP(... | |
CEVolumeFade=createTrackBar(mdA) | |
CEVolumeFade.Left=5 | |
CEVolumeFade.Top=90 | |
CEVolumeFade.Width=295 | |
CEVolumeFade.Height=25 | |
CEVolumeFade.LineSize=1 | |
CEVolumeFade.Frequency=1 | |
CEVolumeFade.Align=alNone | |
CEVolumeFade.Enabled=true | |
CEVolumeFade.Visible=true | |
CEVolumeFade.TabOrder=3 | |
CEVolumeFade.TabStop=true | |
CEVolumeFade.Max=100 | |
CEVolumeFade.Min=0 | |
CEVolumeFade.Position=75 | |
CEVolumeFade.PageSize=2 | |
CEVolumeFade.ScalePos=trTop | |
CEVolumeFade.TickStyle=tsAuto | |
CEVolumeFade.TickMarks=tmBottomRight | |
CEVolumeFade.OnChange=CEVolumeChange | |
]] | |
CEVolumeFade=createTrackBar(mdA) | |
TCOMP(CEVolumeFade,{Left=5,Top=90,Width=295,Height=25,TabOrder=3,TabStop=true,LineSize=1,Frequency=1,Max=100,Min=0,Position=75, | |
PageSize=2,Align=alNone,Enabled=true,Visible=true,ScalePos=trTop,TickStyle=tsAuto,TickMarks=tmBottomRight,OnChange=CEVolumeChange}); | |
--################################# | |
---> CEMP3Label | |
--[[ Edit: -> TCOMP(... | |
CEMP3Label=createLabel(mdA) | |
CEMP3Label.Caption='' | |
CEMP3Label.Top=37 | |
CEMP3Label.Left=13 | |
CEMP3Label.Transparent=true | |
CEMP3Label.Align=alNone | |
CEMP3Label.Enabled=true | |
CEMP3Label.Visible=true | |
CEMP3Label.BidiMode=bdLeftToRight | |
CEMP3Label.Color=0x000000 | |
--> CEMP3Label.font | |
CEMP3Label.Font.Size=10 | |
CEMP3Label.Font.Height=-13 | |
CEMP3Label.Font.Color=0xE63C98 | |
CEMP3Label.Font.Name='Consolas' | |
CEMP3Label.Font.Style='[fsBold]' | |
CEMP3Label.Font.Pitch='fpFixed' | |
CEMP3Label.bringToFront() | |
]]-- | |
CEMP3Label=createLabel(mdA) | |
TCOMP(CEMP3Label,{Caption='',Top=37,Left=13,Align=alNone,Enabled=true,Visible=true, | |
BidiMode=bdLeftToRight,Color=0x000000,Transparent=true,bringToFront}); | |
LBF1=CEMP3Label.Font | |
TCOMP(LBF1,{Size=9,Height=-12,Color=0xE63C98,Name='Consolas',Style='[fsBold]',Pitch='fpFixed'}); | |
--################################# | |
end--> ::END:: | |
--[[ Load MP3 Player Form ]]MP3Player_UI(); | |
mdA.OnDropFiles=function(sender, TempFile) | |
CEStopClick(); | |
FilePath=table.concat(TempFile, ""); | |
print('\nLoad MP3 File via OnDropFile Event..\n'..FilePath); | |
CEPlayClick(); | |
end | |
--[[FIRST LOAD | |
--]]FIRST_LOAD=true; mdA.show(); | |
--[[if FIRST_LOAD==nil then mdA.hide(); | |
--]]TCOMP(LBF1,{Size=9,Height=-12,Color=0x00ff50,Name='Consolas',Style='[fsBold]',Pitch='fpFixed'}); | |
TCOMP(CEMP3Label,{Top=37,Left=13,Caption="None MP3 File Loaded!\nTo Load a MP3, Drag-And-Drop a File in",Transparent=true,bringToFront}); | |
--[[ ::END:: SunShineSilver.mdA Lua Script ]]-- | |
--[[########### SunShineSilver.mdA MP3 Player ############]]-- | |
--[[######################################################]]-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment