Advertisement
MiaMyLove

SunShineSilver.mdA MP3 Player (CE Lua)

Apr 20th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.32 KB | None | 0 0
  1. --[[######################################################]]--
  2. --[[########### SunShineSilver.mdA MP3 Player ############]]--
  3. --[[        ::START:: SunShineSilver.mdA Lua Script       ]]--
  4. --[[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
  5. --[[]]function assSunShineSilverMP3Player()
  6.     --[[-> https://i.imgur.com/I2qRt5v.png  https://i.imgur.com/FFnURJQ.png
  7.     #########################################################################################################
  8.     ---------------------------------------------------------------->
  9.     ################
  10.     [ Requirements ]:
  11.     Header: Mmsystem.h (include Windows.h)
  12.     Library: Winmm.lib
  13.     DLL: Winmm.dll
  14.     ---------------------------------------------------------------->
  15.     #################
  16.     [ MCI Functions ]:
  17.     mciExecute
  18.     mciGetCreatorTask
  19.     mciGetDeviceID
  20.     mciGetDeviceIDFromElementID
  21.     1->mciGetErrorString
  22.     mciGetYieldProc
  23.     2->mciSendCommand
  24.     3-> mciSendString
  25.     mciSetYieldProc
  26.     ---------------------------------------------------------------->
  27.     ##############################
  28.     [ mciGetErrorString function ]
  29.     BOOL mciGetErrorString(DWORD  fdwError,LPTSTR lpszErrorText,UINT cchErrorText);
  30.     fdwError:           Error code returned by the mciSendCommand or mciSendString function.
  31.     lpszErrorText:      Pointer to a buffer that receives a null-terminated string describing the specified error.
  32.     cchErrorText:       Length of the buffer, in characters, pointed to by the lpszErrorText parameter.
  33.     ->  Returns TRUE if successful or FALSE if the error code is not known.
  34.     MCIERROR mciSendCommand & mciSendString
  35.     ->  Returns zero if successful or an error otherwise. The low-order word of the returned DWORD value
  36.         contains the error return value. If the error is device-specific, the high-order word of the return
  37.         value is the driver identifier; otherwise, the high-order word is zero. To retrieve a text description
  38.         of return values, pass the return value to the mciGetErrorString function.
  39.     ---------------------------------------------------------------->
  40.     ##############################
  41.     [ mciSendCommand function ]
  42.     2-> MCIERROR mciSendCommand(MCIDEVICEID IDDevice, UINT uMsg, DWORD_PTR fdwCommand, DWORD_PTR dwParam);
  43.     IDDevice:       Device identifier of the MCI device that is to receive the command message.
  44.                     This parameter is not used with the MCI_OPEN command message.
  45.     uMsg:           Command message. For a list, see Multimedia Commands.
  46.     fdwCommand:     Flags for the command message.
  47.     dwParam:        Pointer to a structure that contains parameters for the command message.
  48.     ---------------------------------------------------------------->
  49.     ##########################
  50.     [ mciSendString function ]
  51.     3-> MCIERROR mciSendString(LPCTSTR lpszCommand, LPTSTR lpszReturnString, UINT cchReturn, HANDLE hwndCallback);
  52.     lpszCommand:        Pointer to a null-terminated string that specifies an MCI command string.
  53.                         For a list, see Multimedia Command Strings.
  54.     lpszReturnString:   Pointer to a buffer that receives return information.
  55.                         If no return information is needed, this parameter can be NULL.
  56.     cchReturn:          Size, in characters, of the return buffer specified by the lpszReturnString parameter.
  57.     hwndCallback:       Handle to a callback window if the "notify" flag was specified in the command string.
  58.     ---------------------------------------------------------------->
  59.     #######################
  60.     [ MCI Command Strings ]:
  61.     "break","capability","capture","close",
  62.     "configure","copy","cue","cut","delete",
  63.     "escape","freeze","index","info","list",
  64.     "load","mark","monitor","open","paste",
  65.     "pause","play","put","quality","realize",
  66.     "record","reserve","restore","resume","save",
  67.     "seek","set","setaudio","settimecode",
  68.     "settuner","setvideo","signal","spin",
  69.     "status","step","stop","sysinfo","undo",
  70.     "unfreeze","update","where","window",
  71.     ---------------------------------------------------------------->
  72.     #MediaFile:
  73.     function fcSendCommand(Command)
  74.         writeStringLocal(msPlayerCommand.Memory          , Command)
  75.         writeBytesLocal (msPlayerCommand.Memory+#Command , 0);
  76.         executeCodeLocal('SunShineSilverMP3Player',msPlayerCommand.Memory);
  77.         return readStringLocal(msPlayerCommand.Memory+1024,100);
  78.     end
  79.     ---------------------------------------------------------------->
  80.     fcSendCommand(string.format('open "%s" type mpegvideo alias MediaFile',FilePath))
  81.     function(lpszCommand,TEXT("open %s %s %s"),lpszDevice,lpszOpenFlags,lpszFlags);
  82.     ---------------------------------------------------------------->
  83.     -> setaudio -> volume to
  84.     function(lpszCommand,TEXT("setaudio %s %s %s"),lpszDeviceID,lpszAudio,lpszFlags);
  85.     volume to factor:
  86.     Sets the average audio volume for both audio channels.
  87.     If the left and right volumes have been set to different values,
  88.     then the ratio of left-to-right volume is approximately unchanged.
  89.     -> play
  90.     function(lpszCommand,TEXT("play %s %s %s"),lpszDeviceID,lpszPlayFlags,lpszFlags);
  91.     -> stop
  92.     function(lpszCommand, TEXT("stop %s %s %s"),lpszDeviceID,lpszStopFlags,lpszFlags);
  93.     -> resume
  94.     function(lpszCommand, TEXT("resume %s %s"),lpszDeviceID,lpszFlags);
  95.     -> pause
  96.     function(lpszCommand,TEXT("pause %s %s"),lpszDeviceID,lpszFlags);
  97.     -> close
  98.     function(lpszCommand, TEXT("close %s %s"),lpszDeviceID,lpszFlags);
  99. #########################################################################################################]]--
  100. if assSunShineSilverMP3Player_Loaded then return true end
  101. if autoAssemble([[loadlibrary(winmm.dll)
  102. alloc(SunShineSilverMP3Player,4096)
  103. registersymbol(SunShineSilverMP3Player)
  104.  
  105. SunShineSilverMP3Player:
  106. lea rsp,[rsp-28]
  107.  
  108. lea rsi,[rcx+400]
  109. mov rdx,0
  110. mov r8,0
  111. mov r9,0
  112. call mciSendStringA
  113. mov rcx,rax
  114. mov rdx,rsi
  115. mov r8,400
  116. call mciGetErrorStringA
  117. lea rsp,[rsp+28]
  118. ret]],true)
  119.     then assSunShineSilverMP3Player_Loaded=true;
  120.         msPlayerCommand=createMemoryStream();
  121.         msPlayerCommand.Size=2048;
  122.     return true; else return false; end
  123. end
  124. function fcSendCommand(Command)
  125.     writeStringLocal(msPlayerCommand.Memory, Command);
  126.     writeBytesLocal (msPlayerCommand.Memory+#Command, 0);
  127.     executeCodeLocal('SunShineSilverMP3Player',msPlayerCommand.Memory);
  128.     return readStringLocal(msPlayerCommand.Memory+1024,100);
  129. end
  130. function fcPlay(FilePath)
  131.     if not assSunShineSilverMP3Player() then return end
  132.     local start_a,start_b,cut_a,cut_b,space,str_end=0,0,0,"","","";
  133.     if FilePath~=nil then
  134.     ---> Input FilePath='C:\\Users\\mdA\\Desktop\\The Boy Rackers - Bla Bla Bla(Original Mix).mp3'
  135.         local str_len=string.len(FilePath);
  136.         for i=0,str_len,1 do--[[--> FilePath(...)removing paths]]
  137.             start_a,start_b=string.find(FilePath, "\\", i, str_len);
  138.             if start_b~=nil then
  139.                 str_end=string.sub(FilePath, start_b+1, str_len-4);
  140.             end
  141.         end--[[--> Output str_end='The Boy Rackers - Bla Bla Bla(Original Mix)']]
  142.         if string.len(str_end)>42 then--[[-->str_end(...)check length,
  143.             if need then substring the last space from the max length]]
  144.             space=string.find(str_end, " ", 30, str_len);
  145.             cut_a=string.sub(str_end, 0, space);
  146.             cut_b=string.sub(str_end, space+1, str_len);
  147.             str_end=cut_a..'\n'..cut_b;
  148.         end--[[--> if true then
  149.         Output --> str_end in 2 lines
  150.  
  151.         'The Boy Rackers - Bla Bla Bla
  152.         (Original Mix)'
  153.  
  154.         #setlabel#end]]
  155.     --[[ Edit: -> TCOMP(...
  156.          CEMP3Label.Caption=str_end
  157.          CEMP3Label.Transparent=true
  158.          CEMP3Label.Top=37
  159.          CEMP3Label.Left=13
  160.          CEMP3Label.bringToFront()]]
  161.         TCOMP(CEMP3Label,{Top=37,Left=13,Caption=tostring(str_end),Transparent=true,bringToFront});
  162.         TCOMP(LBF1,{Size=9,Height=-12,Color=0xE63C98,Name='Consolas',Style='[fsBold]',Pitch='fpFixed'});
  163.         PopUpMessage(string.format('SunShineSilver.mdA MP3 Player v1.0a\n\nMP3 File:\n\n'..str_end..'\n'),2400)
  164.     else
  165.     --[[CEMP3Label.Caption="None MP3 File Loaded!";
  166.         CEMP3Label.bringToFront()
  167.         CEMP3Label.Top=37
  168.         CEMP3Label.Left=13
  169.         CEMP3Label.Transparent=true]]
  170.         TCOMP(CEMP3Label,{Top=37,Left=13,Caption="None MP3 File Loaded!\nTo Load a MP3, Drag-And-Drop a File in",Transparent=true,bringToFront});
  171.         TCOMP(LBF1,{Size=9,Height=-12,Color=0xE63C98,Name='Consolas',Style='[fsBold]',Pitch='fpFixed'});
  172.         PopUpMessage(string.format('SunShineSilver.mdA MP3 Player v1.0a\n\nMP3 File:\n\n'..str_end..'\n'),2400)
  173.     end
  174.    
  175.     fcSendCommand('close MediaFile');
  176.     fcSendCommand(string.format('open "%s" type mpegvideo alias MediaFile',FilePath))
  177.     fcSendCommand('play MediaFile');
  178. end
  179. function fcPause()
  180.     if not assSunShineSilverMP3Player() then return end
  181.     if not MP3PlayerPaused then fcSendCommand('pause MediaFile');MP3PlayerPaused=true;
  182.     else fcSendCommand('resume MediaFile');MP3PlayerPaused=false;end
  183. end
  184. function fcStop() if not assSunShineSilverMP3Player() then return end;fcSendCommand('stop MediaFile');end;
  185. function fcVolume(volume) if not assSunShineSilverMP3Player() then return end;fcSendCommand('setaudio MediaFile volume to '..volume);end;
  186. --[[
  187. local smFileName,smFilePath='','';
  188. smFileName=findTableFile('Danceboy_Spinnin.mp3').Stream;
  189. smFilePath=TrainerOrigin or getMainForm().OpenDialog1.InitialDir
  190. smFilePath=smFilePath..'Danceboy_Spinnin.mp3';
  191. FileCheck=io.open(smFilePath);
  192. if FileCheck==nil then
  193.     smFileName.saveToFile(smFilePath);
  194.     --print('File Does Not Exist!',smFilePath,smFileName);
  195. else
  196.     --print('File Already Exist!\n'..smFilePath..'\nStream '..tostring(smFileName),smFilePath);
  197. end
  198. ]]
  199. function CEPlayClick(sender)fcPlay(FilePath); fcVolume(CEVolumeFade.Position*10);end;
  200. function CEPauseClick(sender) fcPause();end;
  201. function CEStopClick(sender) fcStop();end;
  202. function CEVolumeChange(sender) fcVolume(CEVolumeFade.Position*10);end;
  203. function CECloseClick() closeCE();return caFree;end;
  204. function CreateBackground()
  205. local IMG=createImage(mdA)
  206.       IMG.align=alClient
  207. local NET=getInternet()
  208. local BG=NET.getURL("https://i.imgur.com//hvqbRgT.png")
  209.       NET.destroy()
  210. local SS=createStringStream(BG)
  211.       IMG.Picture.LoadFromStream(SS)
  212.       SS.destroy()
  213.       IMG.transparent=false --IMG.stretch=true
  214.       IMG.sendToBack()
  215. end
  216.  
  217. function PopUpMessage(Text,Time)
  218.     --#################################
  219.     local PopUpForm=createForm(false);
  220.     TCOMP(PopUpForm,{Width=mdA.Width+15,Height=mdA.Height+35,Top=mdA.Top-5,Left=mdA.Left-4,
  221.     BorderStyle='bsNone',FormStyle='fsStayOnTop',Color='clBlack'});
  222.     --#################################
  223.     local PopUpLabel1=createLabel(PopUpForm);
  224.     TCOMP(PopUpLabel1,{Top=6,Left=6,Caption=Text,Color=0x000000});
  225.     local PF1=PopUpLabel1.Font;PopUpLabel1.BorderSpacing.Around=20;
  226.     TCOMP(PF1,{Color=0xE63C98,Size=11,Height=-15,CharSet=1252,Name='Consolas',Style='[fsBold]',Pitch='fpFixed'});
  227.     --#################################
  228.     local PopUp=createTimer(PopUpForm);
  229.     PopUp.Interval=Time;
  230.     PopUp.OnTimer=function() PopUpForm.destroy();end
  231.     PopUpForm.show();
  232. end
  233. function MP3Player_UI()
  234.     --#################################
  235.     --> ::START::
  236.     ---> Form
  237.     --[[ Edit: -> TCOMP(... Compare Tables goto NewForm
  238.     mdA=createForm(true)
  239.     mdA.Caption='SunShineSilver.mdA MP3 Player v1.0a'
  240.     mdA.Position='poScreenCenter'
  241.     mdA.Width=305
  242.     mdA.Height=120
  243.     mdA.Visible=true
  244.     mdA.Color='clBlack'
  245.     mdA.BorderStyle='bsToolWindow'
  246.     mdA.BorderIcons='[biSystemMenu,biMinimize]'
  247.     mdA.PopupMode='pmAuto'
  248.     mdA.ShowInTaskBar='stAlways'
  249.     mdA.Align=alNone
  250.     mdA.Enabled=nil
  251.     mdA.Visible=true
  252.     mdA.AllowDropFiles=true
  253.     mdA.OnClose=CECloseClick
  254.     ]]
  255.     --::NewForm::--
  256.     mdA=createForm(true)
  257.     TCOMP(mdA,{Caption='SunShineSilver.mdA MP3 Player v1.0a',Position='poScreenCenter',
  258.     Width=305,Height=120,Visible=true,Color='clBlack',PopupMode='pmAuto',
  259.     BorderStyle='bsToolWindow',BorderIcons='[biSystemMenu,biMinimize]',ShowInTaskBar='stAlways',
  260.     Align=alNone,Enabled=true,Visible=true,AllowDropFiles=true--[[,OnClose=CECloseClick]]});
  261.     CreateBackground()
  262.     --#################################
  263.     -----> Controls
  264.     ---> CEPlayButton
  265.     --[[ Edit: -> TCOMP(...
  266.     CEPlayButton=createButton(mdA)
  267.     CEPlayButton.Caption='Play'
  268.     CEPlayButton.Left=10
  269.     CEPlayButton.Top=68
  270.     CEPlayButton.Width=40
  271.     CEPlayButton.Height=23
  272.     CEPlayButton.Align=alNone
  273.     CEPlayButton.Enabled=true
  274.     CEPlayButton.Visible=true
  275.     CEPlayButton.BidiMode=bdLeftToRight
  276.     CEPlayButton.TabOrder=0
  277.     CEPlayButton.TabStop=true
  278.     CEPlayButton.OnClick=CEPlayClick
  279.     ]]
  280.     CEPlayButton=createButton(mdA)
  281.     TCOMP(CEPlayButton,{Caption='Play',Left=10,Top=68,Width=40,Height=23,TabOrder=0,TabStop=true,
  282.     Align=alNone,Enabled=true,Visible=true,BidiMode=bdLeftToRight,OnClick=CEPlayClick});
  283.     --#################################
  284.     ---> CEPauseButton
  285.     --[[ Edit: -> TCOMP(...
  286.     CEPauseButton=createButton(mdA)
  287.     CEPauseButton.Caption='Pause'
  288.     CEPauseButton.Left=50
  289.     CEPauseButton.Top=68
  290.     CEPauseButton.Width=40
  291.     CEPauseButton.Height=23
  292.     CEPauseButton.Align=alNone
  293.     CEPauseButton.Enabled=true
  294.     CEPauseButton.Visible=true
  295.     CEPauseButton.BidiMode=bdLeftToRight
  296.     CEPauseButton.TabOrder=1
  297.     CEPauseButton.TabStop=true
  298.     CEPauseButton.OnClick=CEPauseClick
  299.     ]]
  300.     CEPauseButton=createButton(mdA)
  301.     TCOMP(CEPauseButton,{Caption='Pause',Left=50,Top=68,Width=40,Height=23,TabOrder=1,TabStop=true,
  302.     Align=alNone,Enabled=true,Visible=true,Anchors={akTop,akLeft},BidiMode=bdLeftToRight,OnClick=CEPauseClick});
  303.     --#################################
  304.     ---> CEStopButton
  305.     --[[ Edit: -> TCOMP(...
  306.     CEStopButton=createButton(mdA)
  307.     CEStopButton.Caption='Stop'
  308.     CEStopButton.Left=90
  309.     CEStopButton.Top=68
  310.     CEStopButton.Width=40
  311.     CEStopButton.Height=23
  312.     CEStopButton.Align=alNone
  313.     CEStopButton.Enabled=true
  314.     CEStopButton.Visible=true
  315.     CEStopButton.BidiMode=bdLeftToRight
  316.     CEStopButton.TabOrder=2
  317.     CEStopButton.TabStop=true
  318.     CEStopButton.OnClick=CEStopClick
  319.     ]]
  320.     CEStopButton=createButton(mdA)
  321.     TCOMP(CEStopButton,{Caption='Stop',Left=90,Top=68,Width=40,Height=23,TabOrder=2,TabStop=true,
  322.     Align=alNone,Enabled=true,Visible=true,Anchors={akTop,akLeft},BidiMode=bdLeftToRight,OnClick=CEStopClick});
  323.     --#################################
  324.     ---> CEVolumeFade
  325.     --[[ Edit: -> TCOMP(...
  326.     CEVolumeFade=createTrackBar(mdA)
  327.     CEVolumeFade.Left=5
  328.     CEVolumeFade.Top=90
  329.     CEVolumeFade.Width=295
  330.     CEVolumeFade.Height=25
  331.     CEVolumeFade.LineSize=1
  332.     CEVolumeFade.Frequency=1
  333.     CEVolumeFade.Align=alNone
  334.     CEVolumeFade.Enabled=true
  335.     CEVolumeFade.Visible=true
  336.     CEVolumeFade.TabOrder=3
  337.     CEVolumeFade.TabStop=true
  338.     CEVolumeFade.Max=100
  339.     CEVolumeFade.Min=0
  340.     CEVolumeFade.Position=75
  341.     CEVolumeFade.PageSize=2
  342.     CEVolumeFade.ScalePos=trTop
  343.     CEVolumeFade.TickStyle=tsAuto
  344.     CEVolumeFade.TickMarks=tmBottomRight
  345.     CEVolumeFade.OnChange=CEVolumeChange
  346.     ]]
  347.     CEVolumeFade=createTrackBar(mdA)
  348.     TCOMP(CEVolumeFade,{Left=5,Top=90,Width=295,Height=25,TabOrder=3,TabStop=true,
  349.     LineSize=1,Frequency=1,Max=100,Min=0,Position=75,PageSize=2,Align=alNone,Enabled=true,Visible=true,
  350.     Anchors={akTop,akLeft},ScalePos=trTop,TickStyle=tsAuto,TickMarks=tmBottomRight,OnChange=CEVolumeChange});
  351.     --#################################
  352.     ---> CEMP3Label
  353.     --[[ Edit: -> TCOMP(...
  354.     CEMP3Label=createLabel(mdA)
  355.     CEMP3Label.Caption=''
  356.     CEMP3Label.Top=37
  357.     CEMP3Label.Left=13
  358.     CEMP3Label.Transparent=true
  359.     CEMP3Label.Align=alNone
  360.     CEMP3Label.Enabled=true
  361.     CEMP3Label.Visible=true
  362.     CEMP3Label.BidiMode=bdLeftToRight
  363.     CEMP3Label.Color=0x000000
  364.     --> CEMP3Label.font
  365.     CEMP3Label.Font.Size=10
  366.     CEMP3Label.Font.Height=-13
  367.     CEMP3Label.Font.Color=0xE63C98
  368.     CEMP3Label.Font.Name='Consolas'
  369.     CEMP3Label.Font.Style='[fsBold]'
  370.     CEMP3Label.Font.Pitch='fpFixed'
  371.     CEMP3Label.bringToFront()
  372.     ]]--
  373.     CEMP3Label=createLabel(mdA)
  374.     TCOMP(CEMP3Label,{Caption='',Top=37,Left=13,Align=alNone,Enabled=true,Visible=true,
  375.     BidiMode=bdLeftToRight,Color=0x000000,Transparent=true,bringToFront});
  376.     LBF1=CEMP3Label.Font
  377.     TCOMP(LBF1,{Size=9,Height=-12,Color=0xE63C98,Name='Consolas',Style='[fsBold]',Pitch='fpFixed'});
  378.     --#################################
  379.     --> ::END::
  380. end
  381. --[[ Load MP3 Player Form ]]MP3Player_UI();
  382. mdA.OnDropFiles=function(sender, TempFile)
  383.     CEStopClick();
  384.     FilePath=table.concat(TempFile, "");
  385.     print('\nLoad MP3 File via OnDropFile Event..\n'..FilePath);
  386.     CEPlayClick();
  387. end
  388. --[[ FIRST LOAD ]]--
  389. TCOMP(CEMP3Label,{Top=37,Left=13,Caption="None MP3 File Loaded!\nTo Load a MP3, Drag-And-Drop a File in",Transparent=true,bringToFront});
  390. TCOMP(LBF1,{Size=9,Height=-12,Color=0x00ff50,Name='Consolas',Style='[fsBold]',Pitch='fpFixed'});
  391. --[[        ::END:: SunShineSilver.mdA Lua Script         ]]--
  392. --[[########### SunShineSilver.mdA MP3 Player ############]]--
  393. --[[######################################################]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement