m4rcin93 Posted February 25, 2018 Posted February 25, 2018 Hello. I want to add playlist to my MP3 Player. To array i added 3 songs, i wanted to when first song finished, start 2nd song but it doesn't work. It's works only with _soundplay($aaa, 1) - with flag 1, i want do it with flag 0. How to do it? $file = FileReadToArray("file.txt") For $x = 0 To Ubound($file) -1 $test = _Soundplay($file[$x],0) Next
Moderators Melba23 Posted February 25, 2018 Moderators Posted February 25, 2018 m4rcin93, Try opening the files before playing them - this works for me: #include <Array.au3> #include <Sound.au3> $aFile = FileReadToArray("file.txt") ; Add another column _ArrayColInsert($aFile, 1) For $x = 0 To Ubound($aFile) - 1 ; Open each file before playing and store the ID $aFile[$x][1] = _SoundOpen($aFile[$x][0]) ; Now play the file _Soundplay($aFile[$x][1], 0) Sleep(1000) Next ; Close the files when terminated $iStopped = 0 Do For $x = 0 To UBound($aFile) - 1 ; Check if track ended and not already closed If ($aFile[$x][1] <> 1) And (_SoundStatus($aFile[$x][1]) = "stopped") Then ; Close the file _SoundClose($aFile[$x][1]) ; Set the flag to indicate this $iStopped += 1 EndIf Next ; Save the CPU Sleep(1000) Until $iStopped = 3 M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
m4rcin93 Posted February 26, 2018 Author Posted February 26, 2018 Its works for me too but when music playing i can't do anything in program. I can't use buttons, i can't exit program etc. Its works now like function _SoundPlay with flag 1. Have you any other idea for solve this problem?
Moderators Melba23 Posted February 26, 2018 Moderators Posted February 26, 2018 m4rcin93, Quote Have you any other idea for solve this problem? Of course! Run your normal idle loop once the files have been opened and are playing and check every now and again from within that loop (use TimerInit/Diff or Adlib) to see if they have finished and should be closed. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Bilgus Posted February 26, 2018 Posted February 26, 2018 I threw Something together expandcollapse popup#include <Array.au3> #include <Sound.au3> #include <File.au3> ;FileReadToArray("file.txt") $aFile = _FileListToArray(@ScriptDir, "*.mp3", $FLTA_FILES, True) If Not IsArray($aFile) Then MsgBox(0, "SoundPlay", "No Files") Exit EndIf _ArrayDisplay($aFile) _ArrayAdd($aFile, "") $aFile[0] += 1 ; add an extra entry so we can play the last file OnAutoItExitRegister("_exit") Global $iArrPos = 1 Global $bRet ;Main Loop While $iArrPos <= $aFile[0] $bRet = PlayNext($aFile[$iArrPos]) If $bRet == True Then ToolTip($aFile[$iArrPos], 0, 0) Sleep(500) ToolTip("", 0, 0) $iArrPos += 1 EndIf Sleep(500) WEnd Func _exit() PlayNext("", True) EndFunc Func PlayNext($sFile, $bQuit = False) Local Static $aSong[3] = [0, 0, ""] Local Const $iWait = 1000 If $bQuit = False And ($aSong[1] = 0 Or $aSong[0] <= TimerDiff($aSong[1])) Then $aSong[0] = _SoundLength($sFile, 2) + $iWait ConsoleWrite($aSong[0] / 1000 & " Secs" & @CRLF) $aSong[2] = $sFile Sleep(500) If _SoundPlay($aSong[2], 0) <> 1 Then if $aSong[2] <> "" Then MsgBox(0, "error", "Error Playing " & $aSong[2]) $aSong[1] = 0 EndIf $aSong[1] = TimerInit() Return True ElseIf $bQuit = True Then ConsoleWrite("Stopping " & $aSong[2]) _SoundStop($aSong[2]) Else ;ConsoleWrite($aSong[0] & " MS " & TimerDiff($aSong[1]) & @CRLF) EndIf Return False EndFunc You might still need to do the trick with preopening the handles but if you have a lot of files it would be a bad idea to pre-open the whole playlist and instead do it in chunks
CYCho Posted February 26, 2018 Posted February 26, 2018 (edited) When I wanted to learn Autoit, I decided to make my own audio player with it. It took me couple of years to come up with a decent player. Through the process I learned a lot about AutoIt and I am proud to have learned it in my sixties after retirement. My goal with the player was: 1. The player should be a stand-alone, with no need to set up. 2. Upon my selection of a folder the player should play all the music in that folder and/or it's subfolders. 3. I should be able to play the files in alphabetical order or in randomly shuffled order. 4. The player will have a bare minimum of user interface with only absolutely necessary functions. 5. I should be able to hide all its windows and even the task bar thumb nail. 6. All the mouse clicks should have corresponding hot keys, so that functions can be called when the windows are hidden. 7. When I start the program, it should automatically start playing the music it was playing at the time of last closing. My player is named zPlayer in the sense that it is the most ignoble player in the world. I know now there is a mobile player of the same name, but mine came first. I'm attaching the compiled version of my player. The source is poorly coded and I can't recommend it to anyone as a good example, but please tell me if you still want the code. PS: The download of exe or zip format is being prevented by windows, so I'm uploading my code below. Edited February 26, 2018 by CYCho exe format not downloaded zPlayer - A Small Audio and Video Player
Bilgus Posted February 26, 2018 Posted February 26, 2018 CYCHo I think Posting Exes files is a cop out and dangerous for people as well I think I probably speak for everyone in that we'd rather see the code Also.. I ran with the example a bit.. expandcollapse popup#include <Array.au3> #include <Sound.au3> #include <File.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> ;FileReadToArray("file.txt") $aFile = _FileListToArray(@ScriptDir, "*.mp3", $FLTA_FILES, True) If Not IsArray($aFile) Then MsgBox(0, "SoundPlay", "No Files") Exit EndIf _ArrayDisplay($aFile) _ArrayAdd($aFile, "") $aFile[0] += 1 ; add an extra entry so we can play the last file OnAutoItExitRegister("_exit") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 250, 68, 192, 124) $Label1 = GUICtrlCreateLabel("", 5, 1, 240, 20) $ButtonBack = GUICtrlCreateButton("<<", 10, 32, 60, 25) $ButtonStop = GUICtrlCreateButton("Stop", 95, 32, 60, 25) $ButtonFwd = GUICtrlCreateButton(">>", 180, 32, 60, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $iWait = 0 Global $iArrPos = 1 Global $bRet While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonBack $iArrPos -= 2 PlayNext("", True) $iWait = 0 Case $ButtonFwd If $iArrPos = 0 Then $iArrPos = 1 PlayNext("", True) $iWait = 0 Case $ButtonStop PlayNext("", True) $iArrPos = 0 Case Else $iWait += 1 ; just so we don't check constantly EndSwitch If $iWait > 200 Or $iWait = 0 Then $iWait = 1 ;Main Loop If $iArrPos > 0 And $iArrPos <= $aFile[0] Then $bRet = PlayNext($aFile[$iArrPos]) If $bRet == True Then GUICtrlSetData($Label1, SplitFileName($aFile[$iArrPos])) ToolTip($aFile[$iArrPos], 0, 0) Sleep(1500) ToolTip("", 0, 0) $iArrPos += 1 EndIf Else If $iArrPos < 0 Then $iArrPos = 0 GUICtrlSetData($Label1, "") EndIf EndIf WEnd Func _exit() PlayNext("", True) EndFunc ;==>_exit Func PlayNext($sFile, $bQuit = False) Local Enum $eaS_sName = 0, $eaS_iDuration, $eaS_hOpen, $eaS_hTimer Local Static $aSong[4] = ["", 0, 0, 0] Local Const $iWait = 1000 If $bQuit = False And ($aSong[$eaS_hOpen] = 0 Or $aSong[$eaS_iDuration] <= TimerDiff($aSong[$eaS_hTimer])) Then If $aSong[$eaS_hOpen] <> 0 Then _SoundClose($aSong[$eaS_hOpen]) $aSong[$eaS_sName] = $sFile $aSong[$eaS_hOpen] = _SoundOpen($aSong[$eaS_sName]) $aSong[$eaS_iDuration] = _SoundLength($aSong[$eaS_hOpen], 2) + $iWait ConsoleWrite($aSong[$eaS_iDuration] / 1000 & " Secs" & @CRLF) $aSong[3] = $sFile Sleep(500) If _SoundPlay($aSong[$eaS_hOpen], 0) <> 1 Then If $aSong[$eaS_sName] <> "" Then MsgBox(0, "error", "Error Playing " & $aSong[$eaS_sName]) $aSong[$eaS_sName] = "" $aSong[$eaS_iDuration] = 0 _SoundClose($aSong[$eaS_hOpen]) $aSong[$eaS_hOpen] = 0 $aSong[$eaS_hTimer] = 0 Else $aSong[$eaS_hTimer] = TimerInit() EndIf Return True ElseIf $bQuit = True And $aSong[$eaS_hOpen] <> 0 Then ConsoleWrite("Stopping " & $aSong[$eaS_sName] & @CRLF) _SoundStop($aSong[$eaS_hOpen]) $aSong[$eaS_sName] = "" $aSong[$eaS_iDuration] = 0 _SoundClose($aSong[$eaS_hOpen]) $aSong[$eaS_hOpen] = 0 $aSong[$eaS_hTimer] = 0 Else ;;Update elapsed etc EndIf Return False EndFunc ;==>PlayNext Func SplitFileName($FullPath) Local $sDummy, $sFileName, $sExt _PathSplit($FullPath, $sDummy, $sDummy, $sFileName, $sExt) Return $sFileName & "" & $sExt EndFunc ;==>SplitFileName
CYCho Posted February 26, 2018 Posted February 26, 2018 (edited) OK, here is my code. I know there is a lot to improve. I would appreciate any comments or ideas for correction. PS: Please look at the Example Scripts page for the latest version. Edited March 15, 2019 by CYCho zPlayer - A Small Audio and Video Player
Bilgus Posted February 26, 2018 Posted February 26, 2018 Pretty cool I can't get random to work though It just pops up my music folder.. Also Whats up with $sNumbers? I assume thats random numbers for shuffle but rather than that Why not SRandom(@SEC) ;Seed random number generator Random(1, UBound($aList) - 1)
CYCho Posted February 26, 2018 Posted February 26, 2018 (edited) When I use Random(), it had certain routines which I didn't like. So I just took some numbers ffom RANDOM.ORG. Please bear in mind that this project was and still is my learning process without any previous programming background. Edited February 26, 2018 by CYCho zPlayer - A Small Audio and Video Player
Bilgus Posted February 26, 2018 Posted February 26, 2018 If you need unique numbers chck out this specifically the post from jchd
CYCho Posted February 26, 2018 Posted February 26, 2018 Bilgus, thank you for your suggestion. I don't clearly understand what you mean by "can't get random to work though It just pops up my music folder." Can you elaborate it a little more? zPlayer - A Small Audio and Video Player
Bilgus Posted February 26, 2018 Posted February 26, 2018 I press ctrl + Alt + M and It pops up my my music folder rather than randomizing the playlist
CYCho Posted February 27, 2018 Posted February 27, 2018 Please see if you have both zPlayList.txt and zPlaylist-Shuffle.txt files in your music folder. If not, please press Ctrl+Alt+u to update your playlist. zPlayer - A Small Audio and Video Player
m4rcin93 Posted February 27, 2018 Author Posted February 27, 2018 Bilgus, your script is good but i have one more question. I want to add sound via button in GUI and function FileOpenDialog, not on the top script. How can i do it?
Bilgus Posted February 27, 2018 Posted February 27, 2018 create a button and call FileOpenDialog ( "title", "init dir", "filter" [, options = 0 [, "default name" [, hwnd]]] )
careca Posted February 27, 2018 Posted February 27, 2018 There is a lot that can be improved. Nice first try. I prefer a different approach to the playlist, instead of having 2 playlists one for sequencial and the random (random didn't work btw), i think would be better to only have one list, random would jump around the list. Also, would be nice to be able to open the playlist and just double click any item to play. Also, when i close the gui, running as a script, i expect the sound to stop, only stopped when i closed autoit. A music player is hard work, i respect what you did so far. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
CYCho Posted February 27, 2018 Posted February 27, 2018 careca, Thank you for your comments. I really appreciate hearing from an expert like you. I intentionally have 2 playlists, because sometimes I want to know what title comes next and I wnat to make it certain that the random playlist plays all the files. Double click on the playlist currently plays the music. The player can be closed in 3 ways: Ctrl+Alt+End, Click on the GUI player exit button, and tray icon menu. Closing the GUI will not terminate the program. It was one of my concept to let it play the music in the background, while I do other work on the computer, without consuming any of my desktop assets such as the screen and task bar. I tried hard to make the player use as little CPU as possible. Yes, I agree it is a hard task. I am learning a lot by doing this. zPlayer - A Small Audio and Video Player
careca Posted February 27, 2018 Posted February 27, 2018 (edited) Quote I really appreciate hearing from an expert like you Thank you, that's flattering, but im not an expert. There are experts in this forum tho. Quote It was one of my concept to let it play the music in the background What if i close the gui and then want to change the song? or stop it, or change volume? :\ Double click is not working for me, doesn't do anything. What do you want to do next? Quote I am learning a lot by doing this. That's the best thing, i sure did. It's only when you program something, you can appreciate the work done in some applications you see. Sometimes, something small can take a lot of time to implement, and debug. Edited February 27, 2018 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
CYCho Posted February 27, 2018 Posted February 27, 2018 Quote What if i close the gui and then want to change the song? or stop it, or change volume? :\ I use hot keys. Several hot keys are defined in the main window: play/pause, repeat/unrepeat, move forward/backward, volume up/down, show/hide windows, etc. Quote Double click is not working for me, doesn't do anything. I introduced this function rather recently after my system was upgraded to Windows 10, so I could not test this under Windows 7. Are you on Windows 10? Quote What do you want to do next? I am learning how to play videos from a mixed list of local files and internet URIs. I asked a question on this forum, but I have not heard an answer. Maybe it's beyond my scope. zPlayer - A Small Audio and Video Player
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