EliasL Posted Sunday at 07:37 PM Posted Sunday at 07:37 PM (edited) Hi everybody , I hope you are doing great 🙂 I have this project about a Jukebox but my GUI is not working right it's not loading and playing the videos or songs and also it's not saving the info on the .DB file also not showing the albums picture. please help me out I'm a newbe don't know much about programing just a lil bit but just don't know anything about databases or .db just to let you know this is not a comercial software I want to give it out for free to anybody so you are free to use it and mode the code to improve it or to make it yours the code is below just to let you know I have a code for a different version of the software that works meaning play songs and videos expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <ComboConstants.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> #include <GuiComboBox.au3> #include <StaticConstants.au3> #include <SQLite.au3> #include <SQLite.dll.au3> #include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> #include <Misc.au3> ; ============================================================ ; ROCKOLA FOREVER PRO - AutoIt ; Motor multimedia: Windows Media Player ActiveX ; Biblioteca persistente: SQLite ; Modos: Cliente / Administrador ; ============================================================ Opt("GUIOnEventMode", 0) Opt("TrayAutoPause", 0) Global Const $APP_NAME = "ROCKOLA FOREVER PRO" Global Const $DB_FILE = @ScriptDir & "\RockolaForever.db" Global Const $PLAYLIST_FILE = @ScriptDir & "\RockolaForever.m3u" Global Const $ADMIN_PIN_DEFAULT = "1234" Global Const $PRICE_PER_SONG = 1 Global $g_hDB = -1 Global $g_oWMP = 0 Global $g_hGUI = 0 Global $g_bAdmin = False Global $g_iCredits = 0 Global $g_iCurrentTrack = -1 Global $g_iCurrentSongID = -1 Global $g_bRandom = False Global $g_bRepeat = False Global $g_bUpdating = False Global $g_sCurrentCover = "" Global $g_aQueue[1] Global $g_iQueueCount = 0 Global $g_iQueuePos = -1 Global $g_aVisibleIDs[1] Global $g_iVisibleCount = 0 ; Controls Global $idSearch, $idGenre, $idResults, $idRequest Global $idCredits, $idNowPlaying, $idTime, $idProgress Global $idVolume, $idQueue, $idCover, $idStatus Global $idAdmin, $idScan, $idAddFolder, $idAddCredits Global $idAutoStart, $idExit, $idRandom, $idRepeat Global $idRemoveSong, $idRefresh, $idModeClient, $idModeAdmin Global $idPlayerHost _Main() Func _Main() If Not _InitDatabase() Then MsgBox(16, $APP_NAME, "No se pudo iniciar la base de datos SQLite.") Exit EndIf _CreateGUI() _RefreshGenres() _RefreshSongs() _RefreshCredits() While 1 Local $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE, $idExit ExitLoop Case $idSearch _RefreshSongs() Case $idGenre _RefreshSongs() Case $idRequest _RequestSelectedSong() Case $idScan, $idAddFolder If _RequireAdmin() Then _ScanFolder() Case $idAddCredits If _RequireAdmin() Then _AddCreditsDialog() Case $idAutoStart If _RequireAdmin() Then _ToggleAutoStart() Case $idAdmin _AdminLogin() Case $idRefresh _RefreshGenres() _RefreshSongs() _RefreshCredits() Case $idRemoveSong If _RequireAdmin() Then _RemoveSelectedSong() Case $idRandom $g_bRandom = Not $g_bRandom GUICtrlSetData($idRandom, "ALEATORIO: " & _OnOff($g_bRandom)) Case $idRepeat $g_bRepeat = Not $g_bRepeat GUICtrlSetData($idRepeat, "REPETIR: " & _OnOff($g_bRepeat)) Case $idVolume If IsObj($g_oWMP) Then $g_oWMP.settings.volume = GUICtrlRead($idVolume) Case $idModeClient _ShowClientMode() Case $idModeAdmin If _RequireAdmin() Then _ShowAdminMode() Case $idResults ; La selección se procesa con el botón PEDIR CANCIÓN. EndSwitch _UpdatePlayback() Sleep(100) WEnd If IsObj($g_oWMP) Then $g_oWMP.controls.stop() $g_oWMP.close() $g_oWMP = 0 EndIf If $g_hDB <> -1 Then _SQLite_Close() _SQLite_Shutdown() GUIDelete($g_hGUI) EndFunc ; -------------------- DATABASE -------------------- Func _InitDatabase() Global $SQL = _SQLite_Startup() If @error Then Return False $g_hDB = _SQLite_Open($DB_FILE) If @error Then Return False _SQLite_Exec($g_hDB, "PRAGMA journal_mode=WAL;") _SQLite_Exec($g_hDB, "PRAGMA synchronous=NORMAL;") _SQLite_Exec($g_hDB, "CREATE TABLE IF NOT EXISTS songs (" & _ "id INTEGER PRIMARY KEY AUTOINCREMENT," & _ "path TEXT UNIQUE NOT NULL," & _ "title TEXT, artist TEXT, album TEXT, genre TEXT);") _SQLite_Exec($g_hDB, "CREATE INDEX IF NOT EXISTS idx_songs_title ON songs(title);") _SQLite_Exec($g_hDB, "CREATE INDEX IF NOT EXISTS idx_songs_artist ON songs(artist);") _SQLite_Exec($g_hDB, "CREATE INDEX IF NOT EXISTS idx_songs_genre ON songs(genre);") _SQLite_Exec($g_hDB, "CREATE TABLE IF NOT EXISTS settings (key TEXT PRIMARY KEY, value TEXT);") _SQLite_Exec($g_hDB, "INSERT OR IGNORE INTO settings(key,value) VALUES('credits','0');") _SQLite_Exec($g_hDB, "INSERT OR IGNORE INTO settings(key,value) VALUES('admin_pin','" & $ADMIN_PIN_DEFAULT & "');") _SQLite_Exec($g_hDB, "CREATE TABLE IF NOT EXISTS playlog (" & _ "id INTEGER PRIMARY KEY AUTOINCREMENT, song_id INTEGER, played_at TEXT DEFAULT CURRENT_TIMESTAMP);") Return True EndFunc Func _SQLQ($s) Return "'" & StringReplace(String($s), "'", "''") & "'" EndFunc Func _GetSetting($key, $default = "") Local $aResult, $iRows, $iCols _SQLite_GetTable2d( _ $g_hDB, _ "SELECT value FROM settings WHERE key=" & _SQLQ($key) & ";", _ $aResult, _ $iRows, _ $iCols) If @error Then Return $default If UBound($aResult) < 2 Then Return $default Return $aResult[1][0] EndFunc Func _SetSetting($key, $value) _SQLite_Exec($g_hDB, "INSERT OR REPLACE INTO settings(key,value) VALUES(" & _ _SQLQ($key) & "," & _SQLQ($value) & ");") EndFunc Func _RefreshCredits() $g_iCredits = Int(_GetSetting("credits", "0")) GUICtrlSetData($idCredits, "CRÉDITOS DISPONIBLES: " & $g_iCredits) EndFunc ; -------------------- GUI -------------------- Func _CreateGUI() $g_hGUI = GUICreate($APP_NAME, @DesktopWidth, @DesktopHeight, 0, 0, _ BitOR($WS_POPUP, $WS_CLIPCHILDREN)) GUISetBkColor(0x10131B, $g_hGUI) GUICtrlCreateLabel("ROCKOLA FOREVER PRO", 22, 12, 650, 48) GUICtrlSetFont(-1, 27, 800, 0, "Arial") GUICtrlSetColor(-1, 0x00D9FF) GUICtrlCreateLabel("MÚSICA • VIDEO • ENTRETENIMIENTO", 27, 58, 500, 24) GUICtrlSetFont(-1, 11, 600) GUICtrlSetColor(-1, 0xAAB4C5) $idModeClient = GUICtrlCreateButton("MODO CLIENTE", 690, 20, 145, 48) $idModeAdmin = GUICtrlCreateButton("ADMINISTRADOR", 845, 20, 165, 48) $idAdmin = GUICtrlCreateButton("ACCESO ADMIN", 1020, 20, 150, 48) ; Área multimedia. El control ActiveX de WMP se crea en esta zona. GUICtrlCreateLabel("REPRODUCIENDO AHORA", 22, 98, 500, 25) GUICtrlSetFont(-1, 13, 700) GUICtrlSetColor(-1, 0xFFFFFF) $g_oWMP = ObjCreate("WMPlayer.OCX") If Not IsObj($g_oWMP) Then MsgBox(16, $APP_NAME, "Windows Media Player ActiveX no está disponible." & @CRLF & _ "Activa la característica Windows Media Player y vuelve a ejecutar.") Exit EndIf $idPlayerHost = GUICtrlCreateObj($g_oWMP, 22, 130, 700, 410) With $g_oWMP .uiMode = "none" .enableContextMenu = False .settings.autoStart = False .settings.volume = 80 .settings.mute = False .stretchToFit = True .windowlessVideo = True EndWith $idCover = GUICtrlCreatePic("", 750, 130, 160, 160) GUICtrlSetBkColor($idCover, 0x202633) GUICtrlCreateLabel("BIBLIOTECA", 930, 125, 200, 28) GUICtrlSetFont(-1, 14, 700) GUICtrlSetColor(-1, 0x00D9FF) $idSearch = GUICtrlCreateInput("", 930, 160, 330, 42, $ES_AUTOHSCROLL) GUICtrlSetFont($idSearch, 14, 400) GUICtrlSetTip($idSearch, "Buscar por canción o artista") $idGenre = GUICtrlCreateCombo("Todos los géneros", 930, 210, 330, 40, $CBS_DROPDOWNLIST) GUICtrlSetFont($idGenre, 12, 400) $idResults = GUICtrlCreateListView("CANCIÓN|ARTISTA|GÉNERO", 930, 260, 330, 280, _ BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS)) _GUICtrlListView_SetColumnWidth($idResults, 0, 135) _GUICtrlListView_SetColumnWidth($idResults, 1, 110) _GUICtrlListView_SetColumnWidth($idResults, 2, 75) GUICtrlSetFont($idResults, 10, 400) $idNowPlaying = GUICtrlCreateLabel("Selecciona una canción", 22, 552, 760, 30) GUICtrlSetFont($idNowPlaying, 14, 700) GUICtrlSetColor($idNowPlaying, 0xFFFFFF) $idStatus = GUICtrlCreateLabel("SISTEMA LISTO", 22, 585, 500, 22) GUICtrlSetColor($idStatus, 0x00D9FF) $idTime = GUICtrlCreateLabel("00:00 / 00:00", 650, 585, 130, 22) GUICtrlSetColor($idTime, 0xFFFFFF) $idProgress = GUICtrlCreateProgress(22, 610, 760, 14) $idVolume = GUICtrlCreateSlider(22, 638, 240, 35) GUICtrlSetLimit($idVolume, 100, 0) GUICtrlSetData($idVolume, 80) GUICtrlCreateLabel("VOLUMEN", 270, 645, 100, 22) GUICtrlSetColor(-1, 0xFFFFFF) $idQueue = GUICtrlCreateList("", 750, 570, 250, 125) GUICtrlSetBkColor($idQueue, 0x202633) GUICtrlSetColor($idQueue, 0xFFFFFF) $idCredits = GUICtrlCreateLabel("CRÉDITOS: 0", 1015, 535, 250, 28) GUICtrlSetFont($idCredits, 15, 800) GUICtrlSetColor($idCredits, 0xFFD700) $idRequest = GUICtrlCreateButton("PEDIR CANCIÓN (1 CRÉDITO)", 1015, 570, 250, 60) GUICtrlSetFont($idRequest, 15, 800) $idScan = GUICtrlCreateButton("ESCANEAR", 22, 695, 130, 45) $idAddFolder = GUICtrlCreateButton("AGREGAR MÚSICA", 160, 695, 130, 45) $idAddCredits = GUICtrlCreateButton("CRÉDITOS", 298, 695, 130, 45) $idAutoStart = GUICtrlCreateButton("AUTO INICIO", 436, 695, 130, 45) $idRefresh = GUICtrlCreateButton("ACTUALIZAR", 574, 695, 130, 45) $idRemoveSong = GUICtrlCreateButton("ELIMINAR", 712, 695, 130, 45) $idRandom = GUICtrlCreateButton("ALEATORIO: OFF", 850, 695, 130, 45) $idRepeat = GUICtrlCreateButton("REPETIR: OFF", 988, 695, 130, 45) $idExit = GUICtrlCreateButton("SALIR", 1126, 695, 100, 45) _ShowClientMode() GUISetState(@SW_SHOW, $g_hGUI) EndFunc Func _ShowClientMode() $g_bAdmin = False _AdminControls(False) EndFunc Func _ShowAdminMode() $g_bAdmin = True _AdminControls(True) EndFunc Func _AdminControls($show) Local $aControls = [$idScan, $idAddFolder, $idAddCredits, $idAutoStart, $idRemoveSong] For $i = 0 To UBound($aControls) - 1 If $show Then GUICtrlSetState($aControls[$i], $GUI_SHOW) Else GUICtrlSetState($aControls[$i], $GUI_HIDE) EndIf Next EndFunc ; -------------------- LIBRARY -------------------- Func _RefreshGenres() Local $aResult, $rows, $cols _SQLite_GetTable2d( _ $g_hDB, _ "SELECT DISTINCT genre FROM songs WHERE genre<>'' ORDER BY genre;", _ $aResult, _ $rows, _ $cols) If Not @error Then For $i = 1 To UBound($aResult) - 1 _GUICtrlComboBox_AddString($idGenre, $aResult[$i][0]) Next EndIf EndFunc Func _RefreshSongs() If $g_bUpdating Then Return $g_bUpdating = True _GUICtrlListView_DeleteAllItems($idResults) ReDim $g_aVisibleIDs[1] $g_iVisibleCount = 0 Local $search = StringStripWS(GUICtrlRead($idSearch), 3) Local $genre = GUICtrlRead($idGenre) Local $sql = "SELECT id,title,artist,genre FROM songs WHERE 1=1 " If $search <> "" Then $sql &= "AND (title LIKE " & _SQLQ("%" & $search & "%") & _ " OR artist LIKE " & _SQLQ("%" & $search & "%") & _ " OR album LIKE " & _SQLQ("%" & $search & "%") & ") " EndIf If $genre <> "" And $genre <> "Todos los géneros" Then $sql &= "AND genre=" & _SQLQ($genre) & " " EndIf $sql &= "ORDER BY title COLLATE NOCASE LIMIT 3000;" Local $aResult, $rows, $cols _SQLite_GetTable2d($g_hDB, $sql, $aResult, $rows, $cols) If Not @error Then For $i = 1 To UBound($aResult) - 1 Local $id = $aResult[$i][0] Local $title = $aResult[$i][1] Local $artist = $aResult[$i][2] Local $g = $aResult[$i][3] Next EndIf $g_bUpdating = False EndFunc Func _ScanFolder() Local $folder = FileSelectFolder("Selecciona la carpeta principal de música y videos", "") If @error Or $folder = "" Then Return GUICtrlSetData($idStatus, "ESCANEANDO BIBLIOTECA...") Local $patterns = "*.mp3;*.wma;*.wav;*.aac;*.m4a;*.mp4;*.avi;*.wmv;*.mpg;*.mpeg;*.mov;*.asf;*.3gp" Local $files = _FileListToArrayRec($folder, $patterns, $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH) If @error Then MsgBox(48, $APP_NAME, "No se encontraron archivos compatibles.") Return EndIf Local $added = 0 For $i = 1 To $files[0] If _IndexFile($files[$i]) Then $added += 1 If Mod($i, 50) = 0 Then GUICtrlSetData($idStatus, "ESCANEANDO: " & $i & " / " & $files[0]) Sleep(1) EndIf Next _RefreshGenres() _RefreshSongs() GUICtrlSetData($idStatus, "ESCANEO TERMINADO. NUEVOS ARCHIVOS: " & $added) MsgBox(64, $APP_NAME, "Escaneo terminado." & @CRLF & _ "Archivos encontrados: " & $files[0] & @CRLF & _ "Nuevos registros: " & $added) EndFunc Func _IndexFile($path) If Not FileExists($path) Then Return False Local $media = $g_oWMP.newMedia($path) If Not IsObj($media) Then Return False Local $title = $media.getItemInfo("Title") Local $artist = $media.getItemInfo("Author") Local $album = $media.getItemInfo("WM/AlbumTitle") Local $genre = $media.getItemInfo("WM/Genre") If $title = "" Then $title = _FileBaseName($path) If $artist = "" Then $artist = "Artista desconocido" If $album = "" Then $album = "" If $genre = "" Then $genre = "Sin categoría" Local $sql = "INSERT OR IGNORE INTO songs(path,title,artist,album,genre) VALUES(" & _ _SQLQ($path) & "," & _SQLQ($title) & "," & _SQLQ($artist) & "," & _ _SQLQ($album) & "," & _SQLQ($genre) & ");" _SQLite_Exec($g_hDB, $sql) Return (@error = 0) EndFunc Func _FileBaseName($path) Local $name = StringTrimLeft($path, StringInStr($path, "\", 0, -1)) Local $dot = StringInStr($name, ".", 0, -1) If $dot > 0 Then $name = StringLeft($name, $dot - 1) Return $name EndFunc Func _RemoveSelectedSong() Local $sel = _GUICtrlListView_GetSelectedIndices($idResults, True) If Not IsArray($sel) Or $sel[0] = 0 Then Return Local $row = Int($sel[1]) If $row < 0 Or $row >= $g_iVisibleCount Then Return If MsgBox(36, $APP_NAME, "¿Eliminar esta canción de la biblioteca?") <> 6 Then Return _SQLite_Exec($g_hDB, "DELETE FROM songs WHERE id=" & $g_aVisibleIDs[$row] & ";") _RefreshGenres() _RefreshSongs() EndFunc ; -------------------- CREDITS / CUSTOMER REQUESTS -------------------- Func _RequestSelectedSong() Local $sel = _GUICtrlListView_GetSelectedIndices($idResults, True) If Not IsArray($sel) Or $sel[0] = 0 Then MsgBox(48, $APP_NAME, "Primero selecciona una canción.") Return EndIf Local $row = Int($sel[1]) If $row < 0 Or $row >= $g_iVisibleCount Then Return _RefreshCredits() If $g_iCredits < $PRICE_PER_SONG Then MsgBox(48, $APP_NAME, "No tienes créditos suficientes." & @CRLF & _ "Solicita créditos al encargado.") Return EndIf Local $songID = $g_aVisibleIDs[$row] Local $aResult, $rows, $cols _SQLite_GetTable2d( _ $g_hDB, _ "SELECT path,title,artist FROM songs WHERE id=" & $songID & ";", _ $aResult, _ $rows, _ $cols) If @error Then Return If UBound($aResult) < 2 Then Return _QueueSong( _ $songID, _ $aResult[1][0], _ $aResult[1][1], _ $aResult[1][2]) GUICtrlSetData($idStatus, "CANCIÓN AGREGADA A LA COLA") EndFunc Func _QueueSong($songID, $path, $title, $artist) ReDim $g_aQueue[$g_iQueueCount + 1] $g_aQueue[$g_iQueueCount] = $path $g_iQueueCount += 1 GUICtrlSetData($idQueue, $title & " - " & $artist & "|") If $g_iQueuePos = -1 Or Not IsObj($g_oWMP) Or $g_oWMP.playState = 1 Or $g_oWMP.playState = 8 Then $g_iQueuePos = $g_iQueueCount - 1 _PlayPath($path, $songID, $title, $artist) EndIf EndFunc Func _AddCreditsDialog() Local $amount = InputBox("Agregar créditos", "Cantidad de créditos a agregar:", "10") If @error Then Return If Not StringIsInt($amount) Or Int($amount) < 1 Or Int($amount) > 100000 Then MsgBox(48, $APP_NAME, "Introduce una cantidad válida.") Return EndIf _RefreshCredits() _SetSetting("credits", String($g_iCredits + Int($amount))) _RefreshCredits() EndFunc ; -------------------- PLAYER -------------------- Func _PlayPath($path, $songID, $title, $artist) If Not FileExists($path) Then Return $g_iCurrentSongID = $songID $g_oWMP.controls.stop() $g_oWMP.URL = $path $g_oWMP.controls.play() GUICtrlSetData($idNowPlaying, $title & " — " & $artist) GUICtrlSetData($idStatus, "REPRODUCIENDO") _ShowAlbumCover($path) _SQLite_Exec($g_hDB, "INSERT INTO playlog(song_id) VALUES(" & Int($songID) & ");") EndFunc Func _ShowAlbumCover($path) ; Busca carátula local en la carpeta del archivo. ; Nombres aceptados: cover.jpg, folder.jpg, front.jpg, album.jpg Local $folder = StringLeft($path, StringInStr($path, "\", 0, -1)) Local $names[4] = ["cover.jpg", "folder.jpg", "front.jpg", "album.jpg"] Local $cover = "" For $i = 0 To UBound($names) - 1 If FileExists($folder & $names[$i]) Then $cover = $folder & $names[$i] ExitLoop EndIf Next If $cover <> "" Then GUICtrlSetImage($idCover, $cover) $g_sCurrentCover = $cover Else GUICtrlSetImage($idCover, "") $g_sCurrentCover = "" EndIf EndFunc Func _UpdatePlayback() If Not IsObj($g_oWMP) Then Return Local $state = $g_oWMP.playState Local $duration = 0, $position = 0 If IsObj($g_oWMP.currentMedia) Then $duration = Int($g_oWMP.currentMedia.duration) $position = Int($g_oWMP.controls.currentPosition) EndIf If $duration > 0 Then GUICtrlSetData($idProgress, Int(($position / $duration) * 100)) GUICtrlSetData($idTime, _TimeText($position) & " / " & _TimeText($duration)) Else GUICtrlSetData($idProgress, 0) GUICtrlSetData($idTime, "00:00 / 00:00") EndIf Static $lastState = -1 If $state = 8 And $lastState <> 8 Then If $g_bRepeat Then $g_oWMP.controls.play() Else _PlayNextQueued() EndIf EndIf $lastState = $state If $state = 3 Then GUICtrlSetData($idStatus, "REPRODUCIENDO") ElseIf $state = 2 Then GUICtrlSetData($idStatus, "EN PAUSA") ElseIf $state = 1 Then If $g_iQueueCount > 0 Then GUICtrlSetData($idStatus, "LISTO") EndIf EndFunc Func _PlayNextQueued() If $g_iQueueCount = 0 Then Return Local $next = $g_iQueuePos + 1 If $g_bRandom And $g_iQueueCount > 1 Then $next = Random(0, $g_iQueueCount - 1, 1) EndIf If $next >= $g_iQueueCount Then $g_iQueuePos = -1 GUICtrlSetData($idStatus, "COLA TERMINADA") Return EndIf $g_iQueuePos = $next Local $path = $g_aQueue[$next] Local $aResult, $rows, $cols _SQLite_GetTable2d( _ $g_hDB, _ "SELECT id,title,artist FROM songs WHERE path=" & _SQLQ($path) & ";", _ $aResult, _ $rows, _ $cols) If Not @error And UBound($aResult) > 1 Then _PlayPath( _ $path, _ $aResult[1][0], _ $aResult[1][1], _ $aResult[1][2]) Else _PlayPath($path, -1, _FileBaseName($path), "") EndIf EndFunc Func _TimeText($seconds) Return StringFormat("%02d:%02d", Int($seconds / 60), Mod($seconds, 60)) EndFunc ; -------------------- ADMIN / AUTOSTART -------------------- Func _AdminLogin() Local $pin = InputBox("Acceso de administrador", "Introduce el PIN de administrador:") If @error Then Return If $pin = _GetSetting("admin_pin", $ADMIN_PIN_DEFAULT) Then _ShowAdminMode() MsgBox(64, $APP_NAME, "Modo administrador activado.") Else MsgBox(16, $APP_NAME, "PIN incorrecto.") EndIf EndFunc Func _RequireAdmin() If $g_bAdmin Then Return True _AdminLogin() Return $g_bAdmin EndFunc Func _ToggleAutoStart() Local $shortcut = @StartupDir & "\Rockola Forever PRO.lnk" If FileExists($shortcut) Then FileDelete($shortcut) MsgBox(64, $APP_NAME, "Inicio automático desactivado.") Else FileCreateShortcut(@ScriptFullPath, $shortcut, @ScriptDir, "", _ "Rockola Forever PRO", "", "", 0) If FileExists($shortcut) Then MsgBox(64, $APP_NAME, "Inicio automático activado.") Else MsgBox(16, $APP_NAME, "No se pudo crear el acceso directo.") EndIf EndIf EndFunc Func _OnOff($value) If $value Then Return "ON" Return "OFF" EndFunc Edited Sunday at 08:28 PM by EliasL
EliasL Posted Sunday at 07:38 PM Author Posted Sunday at 07:38 PM (edited) this is the code of the different version that I mentioned that works but i wanna go to another level so please help! expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <SliderConstants.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <File.au3> #include <Array.au3> #include <MsgBoxConstants.au3> #include <GuiListBox.au3> Opt("GUIOnEventMode", 0) ; ========================================== ; ROCKOLA FOREVER - REPRODUCTOR MULTIMEDIA ; Motor: Windows Media Player ActiveX ; ========================================== Global $oWMP Global $aPlaylist[1] Global $iTotal = 0 Global $iCurrent = -1 Global $bRandom = False Global $bRepeat = False Global $bChanging = False Global $iLastState = -1 Global $hGUI, $idList, $idVideo Global $idPlay, $idPause, $idStop Global $idNext, $idPrev Global $idAdd, $idFolder, $idRemove Global $idSave, $idLoad, $idRandom, $idRepeat Global $idVolume, $idProgress Global $idTitle, $idTime, $idStatus Global $idFull, $idClear ; ========================================== ; INTERFAZ ; ========================================== $hGUI = GUICreate("ROCKOLA FOREVER | Multimedia Player", 1200, 760) GUISetBkColor(0x10131B, $hGUI) GUICtrlCreateLabel("ROCKOLA FOREVER", 20, 12, 500, 42) GUICtrlSetFont(-1, 25, 800, 0, "Arial") GUICtrlSetColor(-1, 0x00D9FF) GUICtrlCreateLabel("SISTEMA MULTIMEDIA PROFESIONAL", 24, 55, 400, 20) GUICtrlSetFont(-1, 10, 400) GUICtrlSetColor(-1, 0xAAAAAA) ; ========================================== ; REPRODUCTOR DE VIDEO ; ========================================== GUICtrlCreateLabel("PANTALLA MULTIMEDIA", 25, 95, 450, 25) GUICtrlSetFont(-1, 12, 700) GUICtrlSetColor(-1, 0xFFFFFF) $oWMP = ObjCreate("WMPlayer.OCX") If Not IsObj($oWMP) Then MsgBox(16, "Error", "No se pudo iniciar Windows Media Player." & @CRLF & _ "Verifica que esté instalado y registrado.") Exit EndIf $idVideo = GUICtrlCreateObj($oWMP, 20, 125, 760, 430) With $oWMP .uiMode = "none" .enableContextMenu = False .windowlessVideo = True .stretchToFit = True .settings.autoStart = False .settings.volume = 80 .settings.mute = False EndWith ; ========================================== ; LISTA DE CANCIONES ; ========================================== GUICtrlCreateLabel("BIBLIOTECA MUSICAL", 805, 95, 350, 25) GUICtrlSetFont(-1, 13, 700) GUICtrlSetColor(-1, 0x00D9FF) $idList = GUICtrlCreateList("", 800, 125, 380, 430, _ BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOTIFY)) GUICtrlSetBkColor($idList, 0x202633) GUICtrlSetColor($idList, 0xFFFFFF) GUICtrlSetFont($idList, 10, 400, 0, "Arial") ; ========================================== ; INFORMACION DE REPRODUCCION ; ========================================== $idTitle = GUICtrlCreateLabel("Selecciona una canción", 25, 565, 750, 28) GUICtrlSetFont($idTitle, 13, 700) GUICtrlSetColor($idTitle, 0xFFFFFF) $idStatus = GUICtrlCreateLabel("LISTO PARA REPRODUCIR", 25, 598, 400, 20) GUICtrlSetColor($idStatus, 0x00D9FF) $idTime = GUICtrlCreateLabel("00:00 / 00:00", 650, 598, 130, 20) GUICtrlSetColor($idTime, 0xFFFFFF) $idProgress = GUICtrlCreateProgress(25, 625, 755, 12) GUICtrlSetData($idProgress, 0) ; ========================================== ; BOTONES PRINCIPALES ; ========================================== $idPrev = GUICtrlCreateButton("|< ANTERIOR", 25, 660, 130, 42) $idPlay = GUICtrlCreateButton("? REPRODUCIR", 165, 660, 155, 42) $idPause = GUICtrlCreateButton("|| PAUSAR", 330, 660, 120, 42) $idStop = GUICtrlCreateButton("¦ DETENER", 460, 660, 120, 42) $idNext = GUICtrlCreateButton("SIGUIENTE >|", 590, 660, 150, 42) ; ========================================== ; VOLUMEN ; ========================================== GUICtrlCreateLabel("VOLUMEN", 805, 575, 100, 20) GUICtrlSetColor(-1, 0xFFFFFF) $idVolume = GUICtrlCreateSlider(805, 598, 350, 35, $TBS_HORZ) GUICtrlSetLimit($idVolume, 100, 0) GUICtrlSetData($idVolume, 80) ; ========================================== ; BIBLIOTECA Y OPCIONES ; ========================================== $idAdd = GUICtrlCreateButton("+ AGREGAR ARCHIVOS", 805, 650, 175, 38) $idFolder = GUICtrlCreateButton("+ AGREGAR CARPETA", 990, 650, 175, 38) $idRemove = GUICtrlCreateButton("QUITAR", 805, 695, 85, 35) $idClear = GUICtrlCreateButton("LIMPIAR", 895, 695, 85, 35) $idSave = GUICtrlCreateButton("GUARDAR LISTA", 985, 695, 105, 35) $idLoad = GUICtrlCreateButton("CARGAR LISTA", 1095, 695, 85, 35) $idRandom = GUICtrlCreateButton("ALEATORIO: OFF", 800, 50, 130, 30) $idRepeat = GUICtrlCreateButton("REPETIR: OFF", 940, 50, 120, 30) $idFull = GUICtrlCreateButton("PANTALLA COMPLETA", 1070, 50, 120, 30) GUISetState(@SW_SHOW, $hGUI) ; ========================================== ; BUCLE PRINCIPAL ; ========================================== While 1 Local $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $idAdd _AddFiles() Case $idFolder _AddFolder() Case $idRemove _RemoveSelected() Case $idClear _ClearPlaylist() Case $idSave _SavePlaylist() Case $idLoad _LoadPlaylist() Case $idPlay _PlaySelected() Case $idPause $oWMP.controls.pause() Case $idStop $oWMP.controls.stop() Case $idNext _NextTrack() Case $idPrev _PreviousTrack() Case $idRandom $bRandom = Not $bRandom GUICtrlSetData($idRandom, "ALEATORIO: " & _ ($bRandom ? "ON" : "OFF")) Case $idRepeat $bRepeat = Not $bRepeat GUICtrlSetData($idRepeat, "REPETIR: " & _ ($bRepeat ? "ON" : "OFF")) Case $idFull $oWMP.fullScreen = True Case $idVolume $oWMP.settings.volume = GUICtrlRead($idVolume) Case $idList If _GUICtrlListBox_GetCaretIndex($idList) >= 0 Then _PlaySelected() EndIf EndSwitch _UpdatePlayer() Sleep(100) WEnd ; ========================================== ; AGREGAR ARCHIVOS ; ========================================== Func _AddFiles() Local $sFiles = FileOpenDialog( _ "Seleccionar música y videos",@HomePath, "Archivos multimedia (*.mp3;*.wma;*.wav;*.aac;*.m4a;" & "*.mp4;*.avi;*.wmv;*.mpg;*.mpeg;*.mov;*.mkv;*.asf;*.flv;*.3gp)", 4 + 1) If @error Then Return Local $aFiles = StringSplit($sFiles, "|") If $aFiles[0] = 1 Then _AddTrack($sFiles) Else For $i = 2 To $aFiles[0] _AddTrack($aFiles[1] & "\" & $aFiles[$i]) Next EndIf EndFunc ; ========================================== ; AGREGAR CARPETA COMPLETA ; ========================================== Func _AddFolder() Local $sFolder = FileSelectFolder( _ "Selecciona la carpeta musical", "", 1) If @error Then Return Local $aFiles = _FileListToArrayRec( _ $sFolder, _ "*.mp3;*.wma;*.wav;*.aac;*.m4a;*.mp4;*.avi;*.wmv;" & _ "*.mpg;*.mpeg;*.mov;*.mkv;*.asf;*.flv;*.3gp", _ $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH) If @error Then MsgBox(48, "Biblioteca", "No se encontraron archivos multimedia.") Return EndIf For $i = 1 To $aFiles[0] _AddTrack($aFiles[$i]) Next MsgBox(64, "Rockola Forever", _ "Se agregaron " & $aFiles[0] & " archivos.") EndFunc ; ========================================== ; INSERTAR CANCION ; ========================================== Func _AddTrack($sPath) If Not FileExists($sPath) Then Return For $i = 0 To $iTotal - 1 If StringLower($aPlaylist[$i]) = StringLower($sPath) Then Return Next ReDim $aPlaylist[$iTotal + 1] $aPlaylist[$iTotal] = $sPath $iTotal += 1 GUICtrlSetData($idList, $sPath) GUICtrlSetData($idStatus, _ "CANCIONES EN BIBLIOTECA: " & $iTotal) EndFunc ; ========================================== ; REPRODUCIR SELECCION ; ========================================== Func _PlaySelected() Local $iSelected = _GUICtrlListBox_GetCaretIndex($idList) If $iSelected < 0 Or $iSelected >= $iTotal Then Return _PlayTrack($iSelected) EndFunc Func _PlayTrack($iIndex) If $iIndex < 0 Or $iIndex >= $iTotal Then Return If Not FileExists($aPlaylist[$iIndex]) Then Return $iCurrent = $iIndex $bChanging = True $oWMP.controls.stop() $oWMP.URL = $aPlaylist[$iCurrent] $oWMP.controls.play() _GUICtrlListBox_SetCurSel($idList, $iCurrent) GUICtrlSetData($idTitle, _ "REPRODUCIENDO: " & _ StringTrimLeft($aPlaylist[$iCurrent], _ StringInStr($aPlaylist[$iCurrent], "\", 0, -1))) GUICtrlSetData($idStatus, "REPRODUCIENDO") $iLastState = -1 $bChanging = False EndFunc ; ========================================== ; SIGUIENTE CANCION ; ========================================== Func _NextTrack() If $iTotal = 0 Then Return Local $iNext If $bRandom And $iTotal > 1 Then Do $iNext = Random(0, $iTotal - 1, 1) Until $iNext <> $iCurrent Else $iNext = $iCurrent + 1 If $iNext >= $iTotal Then $iNext = 0 EndIf _PlayTrack($iNext) EndFunc ; ========================================== ; CANCION ANTERIOR ; ========================================== Func _PreviousTrack() If $iTotal = 0 Then Return Local $iPrev = $iCurrent - 1 If $iPrev < 0 Then $iPrev = $iTotal - 1 _PlayTrack($iPrev) EndFunc ; ========================================== ; ACTUALIZAR REPRODUCTOR ; ========================================== Func _UpdatePlayer() If Not IsObj($oWMP) Then Return If $bChanging Then Return Local $iState = $oWMP.playState Local $iDuration = 0 Local $iPosition = 0 If IsObj($oWMP.currentMedia) Then $iDuration = Int($oWMP.currentMedia.duration) $iPosition = Int($oWMP.controls.currentPosition) EndIf If $iDuration > 0 Then GUICtrlSetData($idProgress, _ Int(($iPosition / $iDuration) * 100)) GUICtrlSetData($idTime, _ _FormatTime($iPosition) & " / " & _ _FormatTime($iDuration)) Else GUICtrlSetData($idProgress, 0) GUICtrlSetData($idTime, "00:00 / 00:00") EndIf ; Detectar final de canción o video If $iState = 8 And $iLastState <> 8 Then If $bRepeat Then $oWMP.controls.play() Else _NextTrack() EndIf EndIf $iLastState = $iState If $iState = 3 Then GUICtrlSetData($idStatus, "REPRODUCIENDO") ElseIf $iState = 2 Then GUICtrlSetData($idStatus, "EN PAUSA") ElseIf $iState = 1 Then GUICtrlSetData($idStatus, "DETENIDO") EndIf EndFunc ; ========================================== ; FORMATO DE TIEMPO ; ========================================== Func _FormatTime($iSeconds) Local $iMin = Int($iSeconds / 60) Local $iSec = Mod($iSeconds, 60) Return StringFormat("%02d:%02d", $iMin, $iSec) EndFunc ; ========================================== ; QUITAR ELEMENTO ; ========================================== Func _RemoveSelected() Local $iSelected = _GUICtrlListBox_GetCaretIndex($idList) If $iSelected < 0 Or $iSelected >= $iTotal Then Return For $i = $iSelected To $iTotal - 2 $aPlaylist[$i] = $aPlaylist[$i + 1] Next $iTotal -= 1 ReDim $aPlaylist[$iTotal] _RefreshList() If $iCurrent = $iSelected Then $oWMP.controls.stop() $iCurrent = -1 GUICtrlSetData($idTitle, "Selecciona una canción") ElseIf $iCurrent > $iSelected Then $iCurrent -= 1 EndIf EndFunc ; ========================================== ; LIMPIAR BIBLIOTECA ; ========================================== Func _ClearPlaylist() $oWMP.controls.stop() $iTotal = 0 $iCurrent = -1 ReDim $aPlaylist[1] _RefreshList() GUICtrlSetData($idTitle, "Selecciona una canción") GUICtrlSetData($idStatus, "BIBLIOTECA VACIA") EndFunc ; ========================================== ; ACTUALIZAR LISTA ; ========================================== Func _RefreshList() GUICtrlSetData($idList, "") For $i = 0 To $iTotal - 1 GUICtrlSetData($idList, $aPlaylist[$i]) Next GUICtrlSetData($idStatus, _ "CANCIONES EN BIBLIOTECA: " & $iTotal) EndFunc ; ========================================== ; GUARDAR LISTA M3U ; ========================================== Func _SavePlaylist() Local $sFile = FileSaveDialog( _ "Guardar lista de reproducción", _ @MyDocumentsDir, _ "Listas M3U (*.m3u)", 16, "Mi_Rockola.m3u") If @error Then Return If StringRight(StringLower($sFile), 4) <> ".m3u" Then $sFile &= ".m3u" EndIf Local $hFile = FileOpen($sFile, 2) If $hFile = -1 Then Return FileWriteLine($hFile, "#EXTM3U") For $i = 0 To $iTotal - 1 FileWriteLine($hFile, $aPlaylist[$i]) Next FileClose($hFile) MsgBox(64, "Rockola Forever", "Lista guardada correctamente.") EndFunc ; ========================================== ; CARGAR LISTA M3U ; ========================================== Func _LoadPlaylist() Local $sFile = FileOpenDialog( _ "Abrir lista de reproducción", _ @MyDocumentsDir, _ "Listas M3U (*.m3u)", 1) If @error Then Return Local $aLines If Not _FileReadToArray($sFile, $aLines) Then Return _ClearPlaylist() For $i = 1 To $aLines[0] Local $sLine = StringStripWS($aLines[$i], 3) If $sLine = "" Then ContinueLoop If StringLeft($sLine, 1) = "#" Then ContinueLoop If FileExists($sLine) Then _AddTrack($sLine) EndIf Next MsgBox(64, "Rockola Forever", "Lista cargada correctamente.") EndFunc ; ========================================== ; CERRAR PROGRAMA ; ========================================== $oWMP.controls.stop() $oWMP.close() $oWMP = 0 GUIDelete($hGUI) Exit Edited Sunday at 08:29 PM by EliasL
mLipok Posted Monday at 01:31 AM Posted Monday at 01:31 AM did you take a look for: EliasL 1 Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
EliasL Posted Monday at 01:47 AM Author Posted Monday at 01:47 AM (edited) 49 minutes ago, mLipok said: did you take a look for: I have not seen it before, I will take a look at it on my free time. Ok? It seems like I will have to start my code from the scratch. Thanks You though Edited Monday at 02:21 AM by EliasL
CYCho Posted Monday at 09:31 AM Posted Monday at 09:31 AM (edited) I also used WMPlayer.OCX when I first started my own media player in 2009. Then I converted to winmm.dll because it offered more functions and better flexibility. Now I'm using mpv.exe, an open-source player engine, because winmm.dll could not play back a 4K video. Please take a look at my current version of zPlayer. Just for your reference, I'm attaching the last WMPlayer.OCX version of my zPlayer. zPlayer_4004_source.zip Edited Monday at 10:25 AM by CYCho ioa747 and EliasL 1 1 zPlayer - A Small Audio and Video Player
EliasL Posted Monday at 02:17 PM Author Posted Monday at 02:17 PM 4 hours ago, CYCho said: I also used WMPlayer.OCX when I first started my own media player in 2009. Then I converted to winmm.dll because it offered more functions and better flexibility. Now I'm using mpv.exe, an open-source player engine, because winmm.dll could not play back a 4K video. Please take a look at my current version of zPlayer. Just for your reference, I'm attaching the last WMPlayer.OCX version of my zPlayer. zPlayer_4004_source.zip 38.04 kB · 1 download I will take a look at it, thanks!!!
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