Jump to content

Recommended Posts

Posted

Hi, I have a problem with GUICtrlCreatePic(). In topicĀ WMPlayer.ocx how to change the shuttle picture? I wanted to replace the shuttle picture with a custom one (which I sent below the code) but got some weird results.

#include <GuiConstants.au3>
#include <Misc.au3>
Global $Paused = False, $SliderButton = @ScriptDir & "\SliderButton.jpg"

$hGui = GUICreate("Music Player", 400, 75, -1, -1)
$Label1 = GUICtrlCreateButton("", 0, 0, 400, 20)                 ;music name
GUICtrlSetState(-1, $GUI_DISABLE)
$Shuttle = GUICtrlCreatePic($SliderButton, 0, 6, 30, 13)
$PauseButton = GUICtrlCreateButton("Pause", 208, 40, 80, 20)
GUISetOnEvent($PauseButton, "PauseButton")
$PlayButton = GUICtrlCreateButton("Play", 112, 40, 80, 20)
$Progress = GUICtrlCreateLabel("0:00", 4, 25, 45, 20, $SS_LEFT)  ; current media position
$Length = GUICtrlCreateLabel("0:00", 350, 25, 45, 20, $SS_RIGHT) ; media length
GUISetState(@SW_SHOW)

$FilePath = "" ;your music path & .mp3
$oPlayer = ObjCreate("WMPlayer.OCX")
If Not IsObj($oPlayer) Then
    MsgBox(0, "WMPlayer.OCX", "Cannot create a WMP object.", 5)
    GUIDelete($hGui)
    Exit
EndIf

$iPos = 0                       ; x coordinate of $Shuttle control in progress bar
$hDLL = DllOpen("user32.dll")   ; to dectect mouse down on the $Shuttle control
$sliderLength = 380             ; in pixels
$adlibInterval = 250            ; in milliseconds

$oPlayer.Settings.Volume = 100

While 1
    $oPlayer.URL = $FilePath
    $hTimer = TimerInit()
    While $oPlayer.playState <> 3   ; 1 - stopped, 2 - paused, 3 - playing
        If TimerDiff($hTimer) > 3000 Then
            MsgBox(0, "WMPlayer.OCX", $FilePath & @CRLF & @CRLF & "Cannot play this file.", 5)
            ExitLoop
        EndIf
        Sleep(5)
    WEnd
    If $oPlayer.playState <> 3 Then
        ContinueLoop
    EndIf

    $sFile = StringMid($FilePath, StringInStr($FilePath, "\", 0, -1) + 1)
    GUICtrlSetData($Label1, $sFile)
    $mediaLength = Int($oPlayer.currentMedia.Duration) ; in seconds
    GUICtrlSetData($Length, Int($mediaLength / 60) & ":" & StringFormat("%02i", Mod($mediaLength, 60)))
    AdlibRegister("Slider", $adlibInterval)
    $oPlayer.Controls.Pause
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                $oPlayer.Close
                Exit
            Case $PlayButton
                If GUICtrlRead($PlayButton) = "Play" Then
                    $oPlayer.Controls.Play
                    AdlibRegister("Slider")
                    GUICtrlSetData($PlayButton, "Stop")
                Else
                    $oPlayer.Controls.currentPosition = 0
                    $oPlayer.Controls.Pause
                    GUICtrlSetData($PlayButton, "Play")
                EndIf
                If $Paused Then
                    While $Paused
                        Sleep(100)
                    WEnd
                EndIf
            Case $Shuttle
                AdlibUnRegister()
                $x = MouseGetPos(0)
                $xOffset = $x - $iPos
                While _IsPressed("01", $hDLL) = 1
                    $x = MouseGetPos(0)
                    If $x > 380 + $xOffset Then
                        $x = 380 + $xOffset
                    ElseIf $x < $xOffset Then
                        $x = $xOffset
                    EndIf
                    $iPos = $x - $xOffset
                    GUICtrlSetPos($Shuttle, $iPos)
                    Sleep(1)
                WEnd
                $mediaPos = $iPos / $sliderLength * $mediaLength
                $oPlayer.Controls.currentPosition = $mediaPos
                AdlibRegister("Slider", $adlibInterval)
                GUICtrlSetData($PauseButton, "Pause")
        EndSwitch
        If $oPlayer.playState = 1 Then
            ExitLoop
        EndIf
    WEnd
WEnd

Func PauseButton()
    If $Paused = False Then
        $oPlayer.Controls.Pause
        AdlibUnRegister()
        $Paused = True
        GUICtrlSetData($PauseButton, "Resume")
    Else
        $oPlayer.Controls.Play
        AdlibRegister("Slider")
        $Paused = False
        GUICtrlSetData($PauseButton, "Pause")
    EndIf
EndFunc   ;==>PauseButton

Func Slider()
    $mediaPos = $oPlayer.Controls.currentPosition
    $iPos = $mediaPos * $sliderLength / $mediaLength
    GUICtrlSetPos($Shuttle, $iPos)
    GUICtrlSetData($Progress, Int($mediaPos / 60) & ":" & StringFormat("%02i", Mod($mediaPos, 60)))
EndFunc   ;==>Slider

Also how can I set buttons to act like OnEvent button? I tried for $PauseButton but didn't make it. So I didn't do it for $PlayButton and $Shuttle. I want to add some lines from my main source to $PlayButton and since I used while loop in those lines (while the song is not over), I should control song (Pause/Resume, adjust position) anytime I want.

SliderButton.jpeg

Posted

Ok @Nine, I use just GUIGetMsg() buttons in this code:

#include <GuiConstants.au3>
#include <Misc.au3>
Global $SliderButton = @ScriptDir & "\SliderButton.jpg"

$hGui = GUICreate("Music Player", 400, 75, -1, -1)
$Label1 = GUICtrlCreateButton("", 0, 0, 400, 20)                 ;music file name
GUICtrlSetState(-1, $GUI_DISABLE)
$Shuttle = GUICtrlCreatePic($SliderButton, 0, 0, 20, 20)
$PauseButton = GUICtrlCreateButton("Pause", 208, 40, 80, 20)
$PlayButton = GUICtrlCreateButton("Play", 112, 40, 80, 20)
$Progress = GUICtrlCreateLabel("0:00", 4, 25, 45, 20, $SS_LEFT)  ; current media position
$Length = GUICtrlCreateLabel("0:00", 350, 25, 45, 20, $SS_RIGHT) ; media length
GUISetState(@SW_SHOW)

$FilePath = "" ;your music path & .mp3
$oPlayer = ObjCreate("WMPlayer.OCX")
If Not IsObj($oPlayer) Then
    MsgBox(0, "WMPlayer.OCX", "Cannot create a WMP object.", 5)
    GUIDelete($hGui)
    Exit
EndIf

$iPos = 0                       ; x coordinate of $Shuttle control in progress bar
$hDLL = DllOpen("user32.dll")   ; to dectect mouse down on the $Shuttle control
$sliderLength = 370             ; in pixels
$adlibInterval = 250            ; in milliseconds
$oPlayer.URL = ""
$mediaLength = 0
$mediaPos = 0

$oPlayer.Settings.Volume = 100

$oPlayer.URL = $FilePath
$hTimer = TimerInit()
While $oPlayer.playState <> 3       ; 1 - stopped, 2 - paused, 3 - playing
    If TimerDiff($hTimer) > 3000 Then
        MsgBox(0, "WMPlayer.OCX", $FilePath & @CRLF & @CRLF & "Cannot play this file.", 5)
        ExitLoop
    EndIf
    Sleep(5)
WEnd

$sFile = StringMid($FilePath, StringInStr($FilePath, "\", 0, -1) + 1)
GUICtrlSetData($Label1, $sFile)
$mediaLength = Int($oPlayer.currentMedia.Duration)     ; in seconds
GUICtrlSetData($Length, Int($mediaLength / 60) & ":" & StringFormat("%02i", Mod($mediaLength, 60)))
AdlibRegister("Slider", $adlibInterval)
$oPlayer.Controls.Pause
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            $oPlayer.Close
            Exit
        Case $PlayButton
            If GUICtrlRead($PlayButton) = "Play" Then
                $oPlayer.Controls.Play
                AdlibRegister("Slider")
                GUICtrlSetData($PlayButton, "Stop")
            Else
                $oPlayer.Controls.currentPosition = 0
                $oPlayer.Controls.Pause
                GUICtrlSetData($PlayButton, "Play")
            EndIf
        Case $PauseButton
            If GUICtrlRead($PauseButton) = "Pause" Then
                $oPlayer.Controls.Pause
                AdlibUnRegister()
                GUICtrlSetData($PauseButton, "Resume")
            Else
                $oPlayer.Controls.Play
                AdlibRegister("Slider")
                GUICtrlSetData($PauseButton, "Pause")
            EndIf
        Case $Shuttle
            AdlibUnRegister()
            $x = MouseGetPos(0)
            $xOffset = $x - $iPos
            While _IsPressed("01", $hDLL) = 1
                $x = MouseGetPos(0)
                If $x > 380 + $xOffset Then
                    $x = 380 + $xOffset
                ElseIf $x < $xOffset Then
                    $x = $xOffset
                EndIf
                $iPos = $x - $xOffset
                GUICtrlSetPos($Shuttle, $iPos)
                Sleep(1)
            WEnd
            $mediaPos = $iPos / $sliderLength * $mediaLength
            $oPlayer.Controls.currentPosition = $mediaPos
            AdlibRegister("Slider", $adlibInterval)
            GUICtrlSetData($PauseButton, "Pause")
    EndSwitch
    If $oPlayer.playState = 1 Then
        ExitLoop
    EndIf
WEnd

Func Slider()
    $mediaPos = $oPlayer.Controls.currentPosition
    $iPos = $mediaPos * $sliderLength / $mediaLength
    GUICtrlSetPos($Shuttle, $iPos)
    GUICtrlSetData($Progress, Int($mediaPos / 60) & ":" & StringFormat("%02i", Mod($mediaPos, 60)))
EndFunc   ;==>Slider

Still have the problem with "GUICtrlCreatePic".

Posted

Here something you could use :

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Constants.au3>
#include <Misc.au3>
#include <GDIPlus.au3>
#include <Array.au3>

Opt("MustDeclareVars", 1)

Local $tImage
_GDIPlus_Startup()
Local $hImage = _ConvertStringToImage($tImage, 18, 18)
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

Local $hGui = GUICreate("WMPlayer.OCX", 400, 75, -1, -1)
Local $idSongName = GUICtrlCreateButton("", 0, 0, 400, 20)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $Shuttle = GUICtrlCreatePic("", 0, 0, 18, 18)
GUICtrlSendMsg(-1, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
_WinAPI_DeleteObject($hBitmap)
Local $Pause = GUICtrlCreateButton("Pause", 160, 40, 80, 20)
Local $Progress = GUICtrlCreateLabel("0:00", 4, 25, 45, 20, $SS_LEFT) ; current media position
Local $Length = GUICtrlCreateLabel("0:00", 350, 25, 45, 20, $SS_RIGHT) ; media length
GUISetState(@SW_SHOW)

Local $aPlayList[2]     ; Put your own mp3 file paths in this playlist
$aPlayList[0] = 1       ; number of files in the playlist
$aPlayList[1] = "Don Henley - The Boys of Summer.mp3"

For $i = $aPlayList[0] To 1 Step -1
  If Not FileExists($aPlayList[$i]) Then
    _ArrayDelete($aPlayList, $i)
    $aPlayList[0] -= 1
  EndIf
Next
If Not $aPlayList[0] Then Exit MsgBox(0, "WMPlayer.ocx", "None of the files listed in $aPlayList array exists.", 5)

Local $oPlayer = ObjCreate("WMPlayer.OCX")
If Not IsObj($oPlayer) Then Exit MsgBox(0, "WMPlayer.OCX", "Cannot create a WMP object.", 5)

Local $iPos = 0                       ; x coordinate of $Shuttle cntrol in progress bar
Local $hDLL = DllOpen("user32.dll")   ; to dectect mouse down on the $Shuttle control
Local $sliderLength = 380             ; in pixels
Local $adlibInterval = 250            ; in milliseconds
$oPlayer.Settings.Volume = 100

Local $nFile = 0, $sFullPath, $hTimer, $sFile, $mediaLength, $x, $mediaPos, $xOffset
While 1
  $nFile += 1
  If $nFile > $aPlayList[0] Then $nFile = 1
  $sFullPath = $aPlayList[$nFile]

  $oPlayer.URL = $sFullPath
  $hTimer = TimerInit()
  While $oPlayer.playState <> 3     ; 1 - stopped, 2 - paused, 3 - playing
    If TimerDiff($hTimer) > 3000 Then
      MsgBox(0, "WMPlayer.OCX", $sFullPath & @CRLF & @CRLF & "Cannot play this file.", 5)
      ExitLoop
    EndIf
    Sleep(10)
  WEnd
  If $oPlayer.playState <> 3 Then ContinueLoop

  $sFile = StringMid($sFullPath, StringInStr($sFullPath, "\", 0, -1) + 1)
  GUICtrlSetData($idSongName, $sFile)
  $mediaLength = Int($oPlayer.currentMedia.Duration)   ; in seconds
  GUICtrlSetData($Length, Int($mediaLength / 60) & ":" & StringFormat("%02i", Mod($mediaLength, 60)))
  AdlibRegister("Slider", $adlibInterval)

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        $oPlayer.Close()
        Exit
      Case $Pause
        If GUICtrlRead($Pause) = "Pause" Then
          $oPlayer.Controls.Pause
          AdlibUnRegister()
          GUICtrlSetData($Pause, "Resume")
        Else
          $oPlayer.Controls.Play
          AdlibRegister("Slider")
          GUICtrlSetData($Pause, "Pause")
        EndIf
      Case $Shuttle
        AdlibUnRegister()
        $x = MouseGetPos(0)
        $xOffset = $x - $iPos
        While _IsPressed("01", $hDLL) = 1
          $x = MouseGetPos(0)
          If $x > 380 + $xOffset Then
            $x = 380 + $xOffset
          ElseIf $x < $xOffset Then
            $x = $xOffset
          EndIf
          $iPos = $x - $xOffset
          GUICtrlSetPos($Shuttle, $iPos)
          Sleep(10)
        WEnd
        $mediaPos = $iPos / $sliderLength * $mediaLength
        $oPlayer.Controls.currentPosition = $mediaPos
        $oPlayer.Controls.Play
        AdlibRegister("Slider", $adlibInterval)
        GUICtrlSetData($Pause, "Pause")
    EndSwitch
    If $oPlayer.playState = 1 Then ExitLoop
  WEnd
WEnd

Func Slider()
  $mediaPos = $oPlayer.Controls.currentPosition
  $iPos = $mediaPos * $sliderLength / $mediaLength
  GUICtrlSetPos($Shuttle, $iPos)
  GUICtrlSetData($Progress, Int($mediaPos / 60) & ":" & StringFormat("%02i", Mod($mediaPos, 60)))
EndFunc   ;==>Slider

; based on https://www.autoitscript.com/forum/topic/204254-saveretrieve-images-tofrom-text-string/

Func _ConvertStringToImage(ByRef $tBuffer, $iWidth, $iHeight)
  Local Const $IMAGE = "FFF6DAFFFFF1D7FF4E341CFF44311CFF40311EFF493726FF4A3020FF563525FF533121FF52331EFF4E331EFF4B351CFF49351CFF4B351CFF52321FFF473125FFF6F5F7FFE2EDF5FFFFF6DCFF54361DFF78634DFF716350FF7D7361FF746757FF745F50FF7F6557FF836657FF816756FF7C6954FF786A53FF786A54FF7A6954FF806856FF7C6758FF2E271EFFF6F7EEFF4E341CFF826D57FF736A56FF6B6957FF616153FF636156FF756C62FF77695DFF746457FF726555FF6E6655FF6B6754FF6B6755FF6D6655FF726557FF776653FF897455FF4D3610FF4E3B26FF6F614EFF6B6957FF707566FF5C6459FF6E736AFF67655DFF666059FF6F685FFF6D695EFF686A5EFF666A5EFF646B5EFF686A5EFF6D685FFF786A58FF876A43FF5E3B09FF3C2D1AFF786E5CFF656557FF5A6257FF5F6963FF545D5AFF5F6260FF696766FF676362FF656460FF5F6560FF5C675FFF5C6660FF5E6560FF636462FF6F6659FF836A48FF5F3E11FF4B3928FF766959FF615F54FF6A6F66FF5B6461FF666E6EFF5D5F60FF6D6A6CFF696466FF656565FF606665FF5C6765FF5C6666FF5E6666FF636468FF70675EFF826A4CFF573910FF472D1DFF7C6758FF797066FF605E56FF5C5F5DFF636566FF696269FF615960FF6A5F67FF676166FF616266FF5F6364FF5E6366FF5F6266FF656167FF6F635FFF82694FFF53360FFF563526FF785E50FF76685CFF6B655EFF676564FF6B686AFF665E65FF70656FFF6D6068FF6B6068FF666267FF626367FF606368FF646268FF69606AFF746360FF836A50FF563912FF543222FF826556FF756558FF6F685FFF686463FF686365FF6C6169FF6D6068FF6F6068FF6B6068FF666267FF626465FF626367FF646367FF696168FF746360FF846A4CFF583A11FF543320FF7F6554FF736656FF6D695EFF666561FF646464FF696267FF6B6068FF6B6068FF696267FF626465FF606465FF606465FF626465FF686267FF72645EFF826A4EFF563912FF4F341FFF7A6752FF6F6756FF6A6A5EFF606661FF5F6564FF646367FF666267FF666267FF626465FF5F6564FF5B6664FF5B6664FF5F6564FF646365FF6F655EFF7D6852FF513818FF4C361DFF766851FF6C6856FF666A5EFF5F6760FF5D6564FF606367FF626367FF626367FF606465FF5B6664FF596763FF596763FF5D6663FF646563FF6D665DFF7D6852FF513818FF4A361DFF766851FF6C6856FF646B5EFF5D6761FF5B6664FF5F6467FF606367FF626367FF606465FF5B6664FF596763FF5B6761FF5D6761FF646561FF70665CFF806A4EFF563914FF4D351FFF786752FF6E6756FF686A5EFF5F6661FF5D6565FF606368FF646268FF646268FF626465FF5F6564FF5D6663FF5F6661FF626661FF686561FF74665AFF846B4BFF5A3A11FF533320FF7E6654FF736658FF6D685FFF646563FF626465FF666268FF696168FF696168FF686267FF646365FF626563FF646561FF686561FF6F6361FF79655AFF866A4CFF583912FF513322FF7F6554FF766656FF74685CFF6D665DFF6D655EFF706361FF726361FF726361FF726360FF6F6460FF6D655EFF6F665DFF72665CFF77645CFF7D6657FF82694FFF513816FFFFF8E7FF463220FF83705BFF7B6952FF7B6650FF7F6950FF7F674FFF7E664EFF816854FF806854FF7E6954FF7E6954FF7E6954FF806953FF836951FF816953FF483520FFFFF4DEFFFFEFDEFFFFF1DEFF442F19FF483117FF5A4121FF4F3412FF563815FF583C1AFF533617FF523618FF50351AFF50351AFF50351AFF503618FF533518FF4E361AFFF9E9D8FFFFFFF4FF"
  Return _ReadImageFromText($tBuffer, $IMAGE, $iWidth, $iHeight)
EndFunc   ;==>_ConvertStringToImage

Func _ReadImageFromText(ByRef $tByte, $sString, $iWidth, $iHeight, $bFileName = False)
  ; Recreate image from text file
  If $bFileName Then $sString = FileRead($sString)
  Local $dData = Binary("0x" & $sString)
  $tByte = DllStructCreate("byte string[" & $iWidth * $iHeight * 4 & "]")
  DllStructSetData($tByte, 1, $dData)
  Return _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $GDIP_PXF32ARGB, $iWidth * 4, DllStructGetPtr($tByte, "string"))
EndFunc   ;==>_ReadImageFromText

Ā 

Posted

@NineĀ thanks.Ā Can't I put a button instead of a picture? I replace line

$Shuttle = GUICtrlCreatePic($SliderButton, 0, 0, 20, 20)

with:

$Shuttle = GUICtrlCreateButton($SliderButton, 0, 0, 20, 20)

button moves along with the song but since I don't know about moving button with button/picture, can't fix it.

Posted (edited)

The problem with a button is that it only triggersĀ at Key-up.Ā  So the _IsPressed is no longer true.Ā  You will need to register a msg to make it worked with a button or work with mouse state (more complexity).Ā  The real question is why would you want a button instead of a picture ?Ā 

Edited by Nine
Posted (edited)

@NineI think it's easier to work with the button than picture, I am more familiar with the functions of the button. Now I do not know what to do if I want to put the slider in another part of the main source. You didn't even mention the path of the picture in your code and it is complicated for me. I don't want to be lazy, but i there is a way to replace the picture with a button, it will be easier for me to work with.

Edited by Emanoel
Posted

I do not understand why it is easier to work with a button, but here you go :

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Constants.au3>
#include <Misc.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>

Opt("MustDeclareVars", 1)

Local $tImage
_GDIPlus_Startup()
Local $hImage = _ConvertStringToImage($tImage, 18, 18)
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

Local $hGui = GUICreate("WMPlayer.OCX", 400, 75, -1, -1)
Local $idSongName = GUICtrlCreateButton("", 0, 0, 400, 20)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $Shuttle = GUICtrlCreateButton("", 0, 0, 20, 20)
Local $hImageList=_GUIImageList_Create()
_GUIImageList_Add($hImageList, $hBitmap)
_GUICtrlButton_SetImageList($Shuttle, $hImageList)
_WinAPI_DeleteObject($hBitmap)
Local $Pause = GUICtrlCreateButton("Pause", 160, 40, 80, 20)
Local $Progress = GUICtrlCreateLabel("0:00", 4, 25, 45, 20, $SS_LEFT) ; current media position
Local $Length = GUICtrlCreateLabel("0:00", 350, 25, 45, 20, $SS_RIGHT) ; media length
GUISetState(@SW_SHOW)

Local $aPlayList[2]     ; Put your own mp3 file paths in this playlist
$aPlayList[0] = 1       ; number of files in the playlist
$aPlayList[1] = "Don Henley - The Boys of Summer.mp3"

For $i = $aPlayList[0] To 1 Step -1
  If Not FileExists($aPlayList[$i]) Then
    _ArrayDelete($aPlayList, $i)
    $aPlayList[0] -= 1
  EndIf
Next
If Not $aPlayList[0] Then Exit MsgBox(0, "WMPlayer.ocx", "None of the files listed in $aPlayList array exists.", 5)

Local $oPlayer = ObjCreate("WMPlayer.OCX")
If Not IsObj($oPlayer) Then Exit MsgBox(0, "WMPlayer.OCX", "Cannot create a WMP object.", 5)

Local $iPos = 0                       ; x coordinate of $Shuttle cntrol in progress bar
Local $hDLL = DllOpen("user32.dll")   ; to dectect mouse down on the $Shuttle control
Local $sliderLength = 380             ; in pixels
Local $adlibInterval = 250            ; in milliseconds
$oPlayer.Settings.Volume = 100

Local $nFile = 0, $sFullPath, $hTimer, $sFile, $mediaLength, $x, $mediaPos, $xOffset
While 1
  $nFile += 1
  If $nFile > $aPlayList[0] Then $nFile = 1
  $sFullPath = $aPlayList[$nFile]

  $oPlayer.URL = $sFullPath
  $hTimer = TimerInit()
  While $oPlayer.playState <> 3     ; 1 - stopped, 2 - paused, 3 - playing
    If TimerDiff($hTimer) > 3000 Then
      MsgBox(0, "WMPlayer.OCX", $sFullPath & @CRLF & @CRLF & "Cannot play this file.", 5)
      ExitLoop
    EndIf
    Sleep(10)
  WEnd
  If $oPlayer.playState <> 3 Then ContinueLoop

  $sFile = StringMid($sFullPath, StringInStr($sFullPath, "\", 0, -1) + 1)
  GUICtrlSetData($idSongName, $sFile)
  $mediaLength = Int($oPlayer.currentMedia.Duration)   ; in seconds
  GUICtrlSetData($Length, Int($mediaLength / 60) & ":" & StringFormat("%02i", Mod($mediaLength, 60)))
  AdlibRegister("Slider", $adlibInterval)

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        $oPlayer.Close()
        Exit
      Case $Pause
        If GUICtrlRead($Pause) = "Pause" Then
          $oPlayer.Controls.Pause
          AdlibUnRegister()
          GUICtrlSetData($Pause, "Resume")
        Else
          $oPlayer.Controls.Play
          AdlibRegister("Slider")
          GUICtrlSetData($Pause, "Pause")
        EndIf
      Case $GUI_EVENT_PRIMARYDOWN
        If GUIGetCursorInfo()[4] = $Shuttle Then
          AdlibUnRegister()
          $x = MouseGetPos(0)
          $xOffset = $x - $iPos
          While _IsPressed("01", $hDLL) = 1
            $x = MouseGetPos(0)
            If $x > 380 + $xOffset Then
              $x = 380 + $xOffset
            ElseIf $x < $xOffset Then
              $x = $xOffset
            EndIf
            $iPos = $x - $xOffset
            GUICtrlSetPos($Shuttle, $iPos)
            Sleep(10)
          WEnd
          $mediaPos = $iPos / $sliderLength * $mediaLength
          $oPlayer.Controls.currentPosition = $mediaPos
          $oPlayer.Controls.Play
          AdlibRegister("Slider", $adlibInterval)
          GUICtrlSetData($Pause, "Pause")
        EndIf
    EndSwitch
    If $oPlayer.playState = 1 Then ExitLoop
  WEnd
WEnd

Func Slider()
  $mediaPos = $oPlayer.Controls.currentPosition
  $iPos = $mediaPos * $sliderLength / $mediaLength
  GUICtrlSetPos($Shuttle, $iPos)
  GUICtrlSetData($Progress, Int($mediaPos / 60) & ":" & StringFormat("%02i", Mod($mediaPos, 60)))
EndFunc   ;==>Slider

; based on https://www.autoitscript.com/forum/topic/204254-saveretrieve-images-tofrom-text-string/

Func _ConvertStringToImage(ByRef $tBuffer, $iWidth, $iHeight)
  Local Const $IMAGE = "FFF6DAFFFFF1D7FF4E341CFF44311CFF40311EFF493726FF4A3020FF563525FF533121FF52331EFF4E331EFF4B351CFF49351CFF4B351CFF52321FFF473125FFF6F5F7FFE2EDF5FFFFF6DCFF54361DFF78634DFF716350FF7D7361FF746757FF745F50FF7F6557FF836657FF816756FF7C6954FF786A53FF786A54FF7A6954FF806856FF7C6758FF2E271EFFF6F7EEFF4E341CFF826D57FF736A56FF6B6957FF616153FF636156FF756C62FF77695DFF746457FF726555FF6E6655FF6B6754FF6B6755FF6D6655FF726557FF776653FF897455FF4D3610FF4E3B26FF6F614EFF6B6957FF707566FF5C6459FF6E736AFF67655DFF666059FF6F685FFF6D695EFF686A5EFF666A5EFF646B5EFF686A5EFF6D685FFF786A58FF876A43FF5E3B09FF3C2D1AFF786E5CFF656557FF5A6257FF5F6963FF545D5AFF5F6260FF696766FF676362FF656460FF5F6560FF5C675FFF5C6660FF5E6560FF636462FF6F6659FF836A48FF5F3E11FF4B3928FF766959FF615F54FF6A6F66FF5B6461FF666E6EFF5D5F60FF6D6A6CFF696466FF656565FF606665FF5C6765FF5C6666FF5E6666FF636468FF70675EFF826A4CFF573910FF472D1DFF7C6758FF797066FF605E56FF5C5F5DFF636566FF696269FF615960FF6A5F67FF676166FF616266FF5F6364FF5E6366FF5F6266FF656167FF6F635FFF82694FFF53360FFF563526FF785E50FF76685CFF6B655EFF676564FF6B686AFF665E65FF70656FFF6D6068FF6B6068FF666267FF626367FF606368FF646268FF69606AFF746360FF836A50FF563912FF543222FF826556FF756558FF6F685FFF686463FF686365FF6C6169FF6D6068FF6F6068FF6B6068FF666267FF626465FF626367FF646367FF696168FF746360FF846A4CFF583A11FF543320FF7F6554FF736656FF6D695EFF666561FF646464FF696267FF6B6068FF6B6068FF696267FF626465FF606465FF606465FF626465FF686267FF72645EFF826A4EFF563912FF4F341FFF7A6752FF6F6756FF6A6A5EFF606661FF5F6564FF646367FF666267FF666267FF626465FF5F6564FF5B6664FF5B6664FF5F6564FF646365FF6F655EFF7D6852FF513818FF4C361DFF766851FF6C6856FF666A5EFF5F6760FF5D6564FF606367FF626367FF626367FF606465FF5B6664FF596763FF596763FF5D6663FF646563FF6D665DFF7D6852FF513818FF4A361DFF766851FF6C6856FF646B5EFF5D6761FF5B6664FF5F6467FF606367FF626367FF606465FF5B6664FF596763FF5B6761FF5D6761FF646561FF70665CFF806A4EFF563914FF4D351FFF786752FF6E6756FF686A5EFF5F6661FF5D6565FF606368FF646268FF646268FF626465FF5F6564FF5D6663FF5F6661FF626661FF686561FF74665AFF846B4BFF5A3A11FF533320FF7E6654FF736658FF6D685FFF646563FF626465FF666268FF696168FF696168FF686267FF646365FF626563FF646561FF686561FF6F6361FF79655AFF866A4CFF583912FF513322FF7F6554FF766656FF74685CFF6D665DFF6D655EFF706361FF726361FF726361FF726360FF6F6460FF6D655EFF6F665DFF72665CFF77645CFF7D6657FF82694FFF513816FFFFF8E7FF463220FF83705BFF7B6952FF7B6650FF7F6950FF7F674FFF7E664EFF816854FF806854FF7E6954FF7E6954FF7E6954FF806953FF836951FF816953FF483520FFFFF4DEFFFFEFDEFFFFF1DEFF442F19FF483117FF5A4121FF4F3412FF563815FF583C1AFF533617FF523618FF50351AFF50351AFF50351AFF503618FF533518FF4E361AFFF9E9D8FFFFFFF4FF"
  Return _ReadImageFromText($tBuffer, $IMAGE, $iWidth, $iHeight)
EndFunc   ;==>_ConvertStringToImage

Func _ReadImageFromText(ByRef $tByte, $sString, $iWidth, $iHeight, $bFileName = False)
  ; Recreate image from text file
  If $bFileName Then $sString = FileRead($sString)
  Local $dData = Binary("0x" & $sString)
  $tByte = DllStructCreate("byte string[" & $iWidth * $iHeight * 4 & "]")
  DllStructSetData($tByte, 1, $dData)
  Return _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $GDIP_PXF32ARGB, $iWidth * 4, DllStructGetPtr($tByte, "string"))
EndFunc   ;==>_ReadImageFromText

Ā 

Posted

Could you edit your last post and remove the whole quote.Ā  It makes the thread cumbersome for nothing.Ā  Next time just use reply box at the end of the thread.Ā  Thanks.

Posted (edited)

Hi Nine,
I got a little request if you don't mind.
In your 1st script (the one with GUICtrlCreatePic), do you think it would be possible to click anywhere in the button zone area ($idSongName) to move immediately the shuttle at the clicked position ?
This new feature, added to the already existant "shuttle drag" feature, would make this script even more fantastic :)

Thanks in advance.

Edited by pixelsearch
Maybe by using $GUI_EVENT_PRIMARYDOWN unused in your 1st script ?
Posted

@pixelsearchĀ Maybe this ?

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Constants.au3>
#include <Misc.au3>
#include <GDIPlus.au3>
#include <Array.au3>

Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 2)

Local $tImage
_GDIPlus_Startup()
Local $hImage = _ConvertStringToImage($tImage, 18, 18)
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

Local $hGui = GUICreate("WMPlayer.OCX", 400, 75, -1, -1)
Local $idSongName = GUICtrlCreateButton("", 0, 0, 400, 20)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $idShuttle = GUICtrlCreatePic("", 0, 0, 18, 18)
GUICtrlSendMsg(-1, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
_WinAPI_DeleteObject($hBitmap)
Local $idPause = GUICtrlCreateButton("Pause", 160, 40, 80, 20)
Local $idProgress = GUICtrlCreateLabel("0:00", 4, 25, 45, 20, $SS_LEFT) ; current media position
Local $idLength = GUICtrlCreateLabel("0:00", 350, 25, 45, 20, $SS_RIGHT) ; media length
GUISetState(@SW_SHOW)

Local $aPlayList[2]     ; Put your own mp3 file paths in this playlist
$aPlayList[0] = 1       ; number of files in the playlist
$aPlayList[1] = "ZZTop - La Grange.wav"

For $i = $aPlayList[0] To 1 Step -1
  If Not FileExists($aPlayList[$i]) Then
    _ArrayDelete($aPlayList, $i)
    $aPlayList[0] -= 1
  EndIf
Next
If Not $aPlayList[0] Then Exit MsgBox(0, "WMPlayer.ocx", "None of the files listed in $aPlayList array exists.", 5)

Local $oPlayer = ObjCreate("WMPlayer.OCX")
If Not IsObj($oPlayer) Then Exit MsgBox(0, "WMPlayer.OCX", "Cannot create a WMP object.", 5)

Local $iPos = 0                       ; x coordinate of $idShuttle cntrol in progress bar
Local $iSliderLength = 380             ; in pixels
Local $adlibInterval = 250            ; in milliseconds
$oPlayer.Settings.Volume = 100

Local $nFile = 0, $sFullPath, $hTimer, $sFile, $iMediaLength, $x, $iOffset
While 1
  $nFile += 1
  If $nFile > $aPlayList[0] Then $nFile = 1
  $sFullPath = $aPlayList[$nFile]

  $oPlayer.URL = $sFullPath
  $hTimer = TimerInit()
  While $oPlayer.playState <> 3     ; 1 - stopped, 2 - paused, 3 - playing
    If TimerDiff($hTimer) > 3000 Then
      MsgBox(0, "WMPlayer.OCX", $sFullPath & @CRLF & @CRLF & "Cannot play this file.", 5)
      ExitLoop
    EndIf
    Sleep(10)
  WEnd
  If $oPlayer.playState <> 3 Then ContinueLoop

  $sFile = StringMid($sFullPath, StringInStr($sFullPath, "\", 0, -1) + 1)
  GUICtrlSetData($idSongName, $sFile)
  $iMediaLength = Int($oPlayer.currentMedia.Duration)   ; in seconds
  GUICtrlSetData($idLength, Int($iMediaLength / 60) & ":" & StringFormat("%02i", Mod($iMediaLength, 60)))
  AdlibRegister("Slider", $adlibInterval)

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        $oPlayer.Close()
        Exit
      Case $idPause
        If GUICtrlRead($idPause) = "Pause" Then
          $oPlayer.Controls.Pause
          AdlibUnRegister()
          GUICtrlSetData($idPause, "Resume")
        Else
          $oPlayer.Controls.Play
          AdlibRegister("Slider")
          GUICtrlSetData($idPause, "Pause")
        EndIf
      Case $idShuttle
        AdlibUnRegister()
        $x = MouseGetPos(0)
        $iOffset = $x - $iPos
        While _IsPressed("01") = 1
          $x = MouseGetPos(0)
          If $x > $iSliderLength + $iOffset Then
            $x = $iSliderLength + $iOffset
          ElseIf $x < $iOffset Then
            $x = $iOffset
          EndIf
          $iPos = $x - $iOffset
          GUICtrlSetPos($idShuttle, $iPos)
          Sleep(10)
        WEnd
        $oPlayer.Controls.currentPosition = $iPos / $iSliderLength * $iMediaLength
        $oPlayer.Controls.Play
        AdlibRegister("Slider", $adlibInterval)
        GUICtrlSetData($idPause, "Pause")
      Case $GUI_EVENT_PRIMARYDOWN
        If GUIGetCursorInfo()[4] = $idSongName Then
          GUICtrlSetPos($idShuttle, MouseGetPos(0))
          $x = MouseGetPos(0) / $iSliderLength * $iMediaLength
          $oPlayer.Controls.currentPosition = $x > $iMediaLength ? $iMediaLength : $x
          $oPlayer.Controls.Play
        EndIf
    EndSwitch
    If $oPlayer.playState = 1 Then ExitLoop
  WEnd
WEnd

Func Slider()
  Local $iMP = $oPlayer.Controls.currentPosition
  Local $iPos = $iMP * $iSliderLength / $iMediaLength
  GUICtrlSetPos($idShuttle, $iPos)
  GUICtrlSetData($idProgress, Int($iMP / 60) & ":" & StringFormat("%02i", Mod($iMP, 60)))
EndFunc   ;==>Slider

; based on https://www.autoitscript.com/forum/topic/204254-saveretrieve-images-tofrom-text-string/

Func _ConvertStringToImage(ByRef $tBuffer, $iWidth, $iHeight)
  Local Const $IMAGE = "FFF6DAFFFFF1D7FF4E341CFF44311CFF40311EFF493726FF4A3020FF563525FF533121FF52331EFF4E331EFF4B351CFF49351CFF4B351CFF52321FFF473125FFF6F5F7FFE2EDF5FFFFF6DCFF54361DFF78634DFF716350FF7D7361FF746757FF745F50FF7F6557FF836657FF816756FF7C6954FF786A53FF786A54FF7A6954FF806856FF7C6758FF2E271EFFF6F7EEFF4E341CFF826D57FF736A56FF6B6957FF616153FF636156FF756C62FF77695DFF746457FF726555FF6E6655FF6B6754FF6B6755FF6D6655FF726557FF776653FF897455FF4D3610FF4E3B26FF6F614EFF6B6957FF707566FF5C6459FF6E736AFF67655DFF666059FF6F685FFF6D695EFF686A5EFF666A5EFF646B5EFF686A5EFF6D685FFF786A58FF876A43FF5E3B09FF3C2D1AFF786E5CFF656557FF5A6257FF5F6963FF545D5AFF5F6260FF696766FF676362FF656460FF5F6560FF5C675FFF5C6660FF5E6560FF636462FF6F6659FF836A48FF5F3E11FF4B3928FF766959FF615F54FF6A6F66FF5B6461FF666E6EFF5D5F60FF6D6A6CFF696466FF656565FF606665FF5C6765FF5C6666FF5E6666FF636468FF70675EFF826A4CFF573910FF472D1DFF7C6758FF797066FF605E56FF5C5F5DFF636566FF696269FF615960FF6A5F67FF676166FF616266FF5F6364FF5E6366FF5F6266FF656167FF6F635FFF82694FFF53360FFF563526FF785E50FF76685CFF6B655EFF676564FF6B686AFF665E65FF70656FFF6D6068FF6B6068FF666267FF626367FF606368FF646268FF69606AFF746360FF836A50FF563912FF543222FF826556FF756558FF6F685FFF686463FF686365FF6C6169FF6D6068FF6F6068FF6B6068FF666267FF626465FF626367FF646367FF696168FF746360FF846A4CFF583A11FF543320FF7F6554FF736656FF6D695EFF666561FF646464FF696267FF6B6068FF6B6068FF696267FF626465FF606465FF606465FF626465FF686267FF72645EFF826A4EFF563912FF4F341FFF7A6752FF6F6756FF6A6A5EFF606661FF5F6564FF646367FF666267FF666267FF626465FF5F6564FF5B6664FF5B6664FF5F6564FF646365FF6F655EFF7D6852FF513818FF4C361DFF766851FF6C6856FF666A5EFF5F6760FF5D6564FF606367FF626367FF626367FF606465FF5B6664FF596763FF596763FF5D6663FF646563FF6D665DFF7D6852FF513818FF4A361DFF766851FF6C6856FF646B5EFF5D6761FF5B6664FF5F6467FF606367FF626367FF606465FF5B6664FF596763FF5B6761FF5D6761FF646561FF70665CFF806A4EFF563914FF4D351FFF786752FF6E6756FF686A5EFF5F6661FF5D6565FF606368FF646268FF646268FF626465FF5F6564FF5D6663FF5F6661FF626661FF686561FF74665AFF846B4BFF5A3A11FF533320FF7E6654FF736658FF6D685FFF646563FF626465FF666268FF696168FF696168FF686267FF646365FF626563FF646561FF686561FF6F6361FF79655AFF866A4CFF583912FF513322FF7F6554FF766656FF74685CFF6D665DFF6D655EFF706361FF726361FF726361FF726360FF6F6460FF6D655EFF6F665DFF72665CFF77645CFF7D6657FF82694FFF513816FFFFF8E7FF463220FF83705BFF7B6952FF7B6650FF7F6950FF7F674FFF7E664EFF816854FF806854FF7E6954FF7E6954FF7E6954FF806953FF836951FF816953FF483520FFFFF4DEFFFFEFDEFFFFF1DEFF442F19FF483117FF5A4121FF4F3412FF563815FF583C1AFF533617FF523618FF50351AFF50351AFF50351AFF503618FF533518FF4E361AFFF9E9D8FFFFFFF4FF"
  Return _ReadImageFromText($tBuffer, $IMAGE, $iWidth, $iHeight)
EndFunc   ;==>_ConvertStringToImage

Func _ReadImageFromText(ByRef $tByte, $sString, $iWidth, $iHeight, $bFileName = False)
  ; Recreate image from text file
  If $bFileName Then $sString = FileRead($sString)
  Local $dData = Binary("0x" & $sString)
  $tByte = DllStructCreate("byte string[" & $iWidth * $iHeight * 4 & "]")
  DllStructSetData($tByte, 1, $dData)
  Return _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $GDIP_PXF32ARGB, $iWidth * 4, DllStructGetPtr($tByte, "string"))
EndFunc   ;==>_ReadImageFromText

Ā 

Posted (edited)

Nearly, thanks for this try :)
The new feature works very fine, but now the original feature (dragging the shuttle) got a little issue (gladly reproductible)

For example in the pic below :
1) The song just started and we left-click (button down and up) at about 3min
2) The shuttle places itself immediately at the right place (3min) : new feature is ok !
3) Now we left click over the shuttle (button down only, preparing a drag operation) but as soon as the left mouse button is down, the shuttle jumps back to the left, sometimes at the beginning of the song (that's the pic below) or maybe at another place on the left side of the mouse cursor (in case we did additional clicking before, not in this example)
4) For the record, dragging now "on empty" to the right would move the shuttle to the right too, with a constant gap between the cursor position and the shuttle (3min gap in the pic)
5) Only when we finally release the left mouse button, then the shuttle will jump to the right correct position

1870242119_wmplayerissue.png.068271de71156b1cb6d4e9150dfe214c.png

I think we can live with that if it's too hard to fix. It's just that now, one may be surprised when clicking over the shuttle (to prepare a drag operation) and the shuttle is suddenly no more under the cursor but on the left side of the GUI during the drag operation

Sorry if the explanations aren't clear enough, please do not hesitate to ask for more infos or tries.

Edited by pixelsearch
rephrasing some explanations
Posted (edited)

Ok now :

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Constants.au3>
#include <Misc.au3>
#include <GDIPlus.au3>
#include <Array.au3>

Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 2)

Local $tImage
_GDIPlus_Startup()
Local $hImage = _ConvertStringToImage($tImage, 18, 18)
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

Local $hGui = GUICreate("WMPlayer.OCX", 400, 75, -1, -1)
Local $idSongName = GUICtrlCreateButton("", 0, 0, 400, 20)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $idShuttle = GUICtrlCreatePic("", 0, 0, 18, 18)
GUICtrlSendMsg(-1, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
_WinAPI_DeleteObject($hBitmap)
Local $idPause = GUICtrlCreateButton("Pause", 160, 40, 80, 20)
Local $idProgress = GUICtrlCreateLabel("0:00", 4, 25, 45, 20, $SS_LEFT) ; current media position
Local $idLength = GUICtrlCreateLabel("0:00", 350, 25, 45, 20, $SS_RIGHT) ; media length
GUISetState(@SW_SHOW)

Local $aPlayList[2]     ; Put your own mp3 file paths in this playlist
$aPlayList[0] = 1       ; number of files in the playlist
$aPlayList[1] = "ZZTop - La Grange.wav"

For $i = $aPlayList[0] To 1 Step -1
  If Not FileExists($aPlayList[$i]) Then
    _ArrayDelete($aPlayList, $i)
    $aPlayList[0] -= 1
  EndIf
Next
If Not $aPlayList[0] Then Exit MsgBox(0, "WMPlayer.ocx", "None of the files listed in $aPlayList array exists.", 5)

Local $oPlayer = ObjCreate("WMPlayer.OCX")
If Not IsObj($oPlayer) Then Exit MsgBox(0, "WMPlayer.OCX", "Cannot create a WMP object.", 5)

Local $iSliderLength = 380             ; in pixels
Local $adlibInterval = 250            ; in milliseconds
$oPlayer.Settings.Volume = 100

Local $nFile = 0, $sFullPath, $hTimer, $sFile, $iMediaLength, $x
While 1
  $nFile += 1
  If $nFile > $aPlayList[0] Then $nFile = 1
  $sFullPath = $aPlayList[$nFile]

  $oPlayer.URL = $sFullPath
  $hTimer = TimerInit()
  While $oPlayer.playState <> 3     ; 1 - stopped, 2 - paused, 3 - playing
    If TimerDiff($hTimer) > 3000 Then
      MsgBox(0, "WMPlayer.OCX", $sFullPath & @CRLF & @CRLF & "Cannot play this file.", 5)
      ExitLoop
    EndIf
    Sleep(10)
  WEnd
  If $oPlayer.playState <> 3 Then ContinueLoop

  $sFile = StringMid($sFullPath, StringInStr($sFullPath, "\", 0, -1) + 1)
  GUICtrlSetData($idSongName, $sFile)
  $iMediaLength = Int($oPlayer.currentMedia.Duration)   ; in seconds
  GUICtrlSetData($idLength, Int($iMediaLength / 60) & ":" & StringFormat("%02i", Mod($iMediaLength, 60)))
  AdlibRegister(Slider, $adlibInterval)

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        $oPlayer.Close()
        Exit
      Case $idPause
        If GUICtrlRead($idPause) = "Pause" Then
          $oPlayer.Controls.Pause
          AdlibUnRegister()
          GUICtrlSetData($idPause, "Resume")
        Else
          $oPlayer.Controls.Play
          AdlibRegister(Slider)
          GUICtrlSetData($idPause, "Pause")
        EndIf
      Case $idShuttle
        AdlibUnRegister()
        While _IsPressed("01")
          $x = MouseGetPos(0)
          GUICtrlSetPos($idShuttle, $x)
          Sleep(10)
        WEnd
        $oPlayer.Controls.currentPosition = $x / $iSliderLength * $iMediaLength
        $oPlayer.Controls.Play
        AdlibRegister(Slider, $adlibInterval)
        GUICtrlSetData($idPause, "Pause")
      Case $GUI_EVENT_PRIMARYDOWN
        If GUIGetCursorInfo()[4] = $idSongName Then
          GUICtrlSetPos($idShuttle, MouseGetPos(0))
          $x = MouseGetPos(0) / $iSliderLength * $iMediaLength
          $oPlayer.Controls.currentPosition = $x > $iMediaLength ? $iMediaLength : $x
          $oPlayer.Controls.Play
        EndIf
    EndSwitch
    If $oPlayer.playState = 1 Then ExitLoop
  WEnd
WEnd

Func Slider()
  Local $iMP = $oPlayer.Controls.currentPosition
  Local $iPos = $iMP * $iSliderLength / $iMediaLength
  GUICtrlSetPos($idShuttle, $iPos)
  GUICtrlSetData($idProgress, Int($iMP / 60) & ":" & StringFormat("%02i", Mod($iMP, 60)))
EndFunc   ;==>Slider

; based on https://www.autoitscript.com/forum/topic/204254-saveretrieve-images-tofrom-text-string/

Func _ConvertStringToImage(ByRef $tBuffer, $iWidth, $iHeight)
  Local Const $IMAGE = "FFF6DAFFFFF1D7FF4E341CFF44311CFF40311EFF493726FF4A3020FF563525FF533121FF52331EFF4E331EFF4B351CFF49351CFF4B351CFF52321FFF473125FFF6F5F7FFE2EDF5FFFFF6DCFF54361DFF78634DFF716350FF7D7361FF746757FF745F50FF7F6557FF836657FF816756FF7C6954FF786A53FF786A54FF7A6954FF806856FF7C6758FF2E271EFFF6F7EEFF4E341CFF826D57FF736A56FF6B6957FF616153FF636156FF756C62FF77695DFF746457FF726555FF6E6655FF6B6754FF6B6755FF6D6655FF726557FF776653FF897455FF4D3610FF4E3B26FF6F614EFF6B6957FF707566FF5C6459FF6E736AFF67655DFF666059FF6F685FFF6D695EFF686A5EFF666A5EFF646B5EFF686A5EFF6D685FFF786A58FF876A43FF5E3B09FF3C2D1AFF786E5CFF656557FF5A6257FF5F6963FF545D5AFF5F6260FF696766FF676362FF656460FF5F6560FF5C675FFF5C6660FF5E6560FF636462FF6F6659FF836A48FF5F3E11FF4B3928FF766959FF615F54FF6A6F66FF5B6461FF666E6EFF5D5F60FF6D6A6CFF696466FF656565FF606665FF5C6765FF5C6666FF5E6666FF636468FF70675EFF826A4CFF573910FF472D1DFF7C6758FF797066FF605E56FF5C5F5DFF636566FF696269FF615960FF6A5F67FF676166FF616266FF5F6364FF5E6366FF5F6266FF656167FF6F635FFF82694FFF53360FFF563526FF785E50FF76685CFF6B655EFF676564FF6B686AFF665E65FF70656FFF6D6068FF6B6068FF666267FF626367FF606368FF646268FF69606AFF746360FF836A50FF563912FF543222FF826556FF756558FF6F685FFF686463FF686365FF6C6169FF6D6068FF6F6068FF6B6068FF666267FF626465FF626367FF646367FF696168FF746360FF846A4CFF583A11FF543320FF7F6554FF736656FF6D695EFF666561FF646464FF696267FF6B6068FF6B6068FF696267FF626465FF606465FF606465FF626465FF686267FF72645EFF826A4EFF563912FF4F341FFF7A6752FF6F6756FF6A6A5EFF606661FF5F6564FF646367FF666267FF666267FF626465FF5F6564FF5B6664FF5B6664FF5F6564FF646365FF6F655EFF7D6852FF513818FF4C361DFF766851FF6C6856FF666A5EFF5F6760FF5D6564FF606367FF626367FF626367FF606465FF5B6664FF596763FF596763FF5D6663FF646563FF6D665DFF7D6852FF513818FF4A361DFF766851FF6C6856FF646B5EFF5D6761FF5B6664FF5F6467FF606367FF626367FF606465FF5B6664FF596763FF5B6761FF5D6761FF646561FF70665CFF806A4EFF563914FF4D351FFF786752FF6E6756FF686A5EFF5F6661FF5D6565FF606368FF646268FF646268FF626465FF5F6564FF5D6663FF5F6661FF626661FF686561FF74665AFF846B4BFF5A3A11FF533320FF7E6654FF736658FF6D685FFF646563FF626465FF666268FF696168FF696168FF686267FF646365FF626563FF646561FF686561FF6F6361FF79655AFF866A4CFF583912FF513322FF7F6554FF766656FF74685CFF6D665DFF6D655EFF706361FF726361FF726361FF726360FF6F6460FF6D655EFF6F665DFF72665CFF77645CFF7D6657FF82694FFF513816FFFFF8E7FF463220FF83705BFF7B6952FF7B6650FF7F6950FF7F674FFF7E664EFF816854FF806854FF7E6954FF7E6954FF7E6954FF806953FF836951FF816953FF483520FFFFF4DEFFFFEFDEFFFFF1DEFF442F19FF483117FF5A4121FF4F3412FF563815FF583C1AFF533617FF523618FF50351AFF50351AFF50351AFF503618FF533518FF4E361AFFF9E9D8FFFFFFF4FF"
  Return _ReadImageFromText($tBuffer, $IMAGE, $iWidth, $iHeight)
EndFunc   ;==>_ConvertStringToImage

Func _ReadImageFromText(ByRef $tByte, $sString, $iWidth, $iHeight, $bFileName = False)
  ; Recreate image from text file
  If $bFileName Then $sString = FileRead($sString)
  Local $dData = Binary("0x" & $sString)
  $tByte = DllStructCreate("byte string[" & $iWidth * $iHeight * 4 & "]")
  DllStructSetData($tByte, 1, $dData)
  Return _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $GDIP_PXF32ARGB, $iWidth * 4, DllStructGetPtr($tByte, "string"))
EndFunc   ;==>_ReadImageFromText

Ā 

Edited by Nine
Posted (edited)

I remember that one at the second I read its title, haven't listened to it for decades !
It had something to do with a "neuro surgeon screaming for more" or something approaching lol

Edit1: During those days, I also liked "You keep me hanging on" by... Vanilla Fudge

Edit2 (and last) : as the thread drifted a bit about music, I'll just add that I like it when performers cover a song in a personal way, especially by changing its rythm. It may not always be a successful attempt but for example, "You keep me hanging on" performed by Vanilla Fudge or by Rod Stewart are great covers, very different of the original by the Supremes. That's also the case for "With a little help from my friends" by Joe Cocker, which is great too, while being so different from the Beatles original. Same goes for "America" from Simon & Garfunkel, covered by Yes (Jon Anderson's incredible voice). These are 3 examples among many others !

Edited by pixelsearch
Posted (edited)

Just a small detail on @Nine's code: I thought it woudĀ be good to alignĀ the mouse position with the center of shuttle. So here it is:
Ā 

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <Constants.au3>
#include <Misc.au3>
#include <GDIPlus.au3>
#include <Array.au3>

Opt("MustDeclareVars", 1)
Opt("MouseCoordMode", 2)

Local $tImage
_GDIPlus_Startup()
Local $hImage = _ConvertStringToImage($tImage, 18, 18)
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

Local $hGui = GUICreate("WMPlayer.OCX", 400, 75, -1, -1)
Local $idSongName = GUICtrlCreateButton("", 0, 0, 400, 20)
GUICtrlSetState(-1, $GUI_DISABLE)
Local $iShuttleWidth = 18
Local $idShuttle = GUICtrlCreatePic("", 0, 0, $iShuttleWidth, 18)
GUICtrlSendMsg(-1, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)
_WinAPI_DeleteObject($hBitmap)
Local $idPause = GUICtrlCreateButton("Pause", 160, 40, 80, 20)
Local $idProgress = GUICtrlCreateLabel("0:00", 4, 25, 45, 20, $SS_LEFT) ; current media position
Local $idLength = GUICtrlCreateLabel("0:00", 350, 25, 45, 20, $SS_RIGHT) ; media length
GUISetState(@SW_SHOW)

Local $aPlayList[2]     ; Put your own mp3 file paths in this playlist
$aPlayList[0] = 1       ; number of files in the playlist
$aPlayList[1] = "C:\Users\CYCho\Downloads\King Crimson - 21st Century Schizoid Man.mp3"

For $i = $aPlayList[0] To 1 Step -1
  If Not FileExists($aPlayList[$i]) Then
    _ArrayDelete($aPlayList, $i)
    $aPlayList[0] -= 1
  EndIf
Next
If Not $aPlayList[0] Then Exit MsgBox(0, "WMPlayer.ocx", "None of the files listed in $aPlayList array exists.", 5)

Local $oPlayer = ObjCreate("WMPlayer.OCX")
If Not IsObj($oPlayer) Then Exit MsgBox(0, "WMPlayer.OCX", "Cannot create a WMP object.", 5)

Local $iSliderLength = 380            ; in pixels
Local $adlibInterval = 250            ; in milliseconds
$oPlayer.Settings.Volume = 100

Local $nFile = 0, $sFullPath, $hTimer, $sFile, $iMediaLength, $x
While 1
  $nFile += 1
  If $nFile > $aPlayList[0] Then $nFile = 1
  $sFullPath = $aPlayList[$nFile]

  $oPlayer.URL = $sFullPath
  $hTimer = TimerInit()
  While $oPlayer.playState <> 3     ; 1 - stopped, 2 - paused, 3 - playing
    If TimerDiff($hTimer) > 3000 Then
      MsgBox(0, "WMPlayer.OCX", $sFullPath & @CRLF & @CRLF & "Cannot play this file.", 5)
      ExitLoop
    EndIf
    Sleep(10)
  WEnd
  If $oPlayer.playState <> 3 Then ContinueLoop

  $sFile = StringMid($sFullPath, StringInStr($sFullPath, "\", 0, -1) + 1)
  GUICtrlSetData($idSongName, $sFile)
  $iMediaLength = Int($oPlayer.currentMedia.Duration)   ; in seconds
  GUICtrlSetData($idLength, Int($iMediaLength / 60) & ":" & StringFormat("%02i", Mod($iMediaLength, 60)))
  AdlibRegister(Slider, $adlibInterval)

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        $oPlayer.Close()
        Exit
      Case $idPause
        If GUICtrlRead($idPause) = "Pause" Then
          $oPlayer.Controls.Pause
          AdlibUnRegister()
          GUICtrlSetData($idPause, "Resume")
        Else
          $oPlayer.Controls.Play
          AdlibRegister(Slider)
          GUICtrlSetData($idPause, "Pause")
        EndIf
      Case $idShuttle
        AdlibUnRegister()
        While _IsPressed("01")
          $x = MouseGetPos(0)
          GUICtrlSetPos($idShuttle, $x-$iShuttleWidth/2)
          Sleep(10)
        WEnd
        $oPlayer.Controls.currentPosition = ($x-$iShuttleWidth/2) / $iSliderLength * $iMediaLength
        $oPlayer.Controls.Play
        AdlibRegister(Slider, $adlibInterval)
        GUICtrlSetData($idPause, "Pause")
      Case $GUI_EVENT_PRIMARYDOWN
        If GUIGetCursorInfo()[4] = $idSongName Then
          GUICtrlSetPos($idShuttle, MouseGetPos(0)-$iShuttleWidth/2)
          $x = (MouseGetPos(0)-$iShuttleWidth/2) / $iSliderLength * $iMediaLength
          $oPlayer.Controls.currentPosition = $x > $iMediaLength ? $iMediaLength : $x
          $oPlayer.Controls.Play
        EndIf
    EndSwitch
    If $oPlayer.playState = 1 Then ExitLoop
  WEnd
WEnd

Func Slider()
  Local $iMP = $oPlayer.Controls.currentPosition
  Local $iPos = $iMP * $iSliderLength / $iMediaLength
  GUICtrlSetPos($idShuttle, $iPos)
  GUICtrlSetData($idProgress, Int($iMP / 60) & ":" & StringFormat("%02i", Mod($iMP, 60)))
EndFunc   ;==>Slider

; based on https://www.autoitscript.com/forum/topic/204254-saveretrieve-images-tofrom-text-string/

Func _ConvertStringToImage(ByRef $tBuffer, $iWidth, $iHeight)
  Local Const $IMAGE = "FFF6DAFFFFF1D7FF4E341CFF44311CFF40311EFF493726FF4A3020FF563525FF533121FF52331EFF4E331EFF4B351CFF49351CFF4B351CFF52321FFF473125FFF6F5F7FFE2EDF5FFFFF6DCFF54361DFF78634DFF716350FF7D7361FF746757FF745F50FF7F6557FF836657FF816756FF7C6954FF786A53FF786A54FF7A6954FF806856FF7C6758FF2E271EFFF6F7EEFF4E341CFF826D57FF736A56FF6B6957FF616153FF636156FF756C62FF77695DFF746457FF726555FF6E6655FF6B6754FF6B6755FF6D6655FF726557FF776653FF897455FF4D3610FF4E3B26FF6F614EFF6B6957FF707566FF5C6459FF6E736AFF67655DFF666059FF6F685FFF6D695EFF686A5EFF666A5EFF646B5EFF686A5EFF6D685FFF786A58FF876A43FF5E3B09FF3C2D1AFF786E5CFF656557FF5A6257FF5F6963FF545D5AFF5F6260FF696766FF676362FF656460FF5F6560FF5C675FFF5C6660FF5E6560FF636462FF6F6659FF836A48FF5F3E11FF4B3928FF766959FF615F54FF6A6F66FF5B6461FF666E6EFF5D5F60FF6D6A6CFF696466FF656565FF606665FF5C6765FF5C6666FF5E6666FF636468FF70675EFF826A4CFF573910FF472D1DFF7C6758FF797066FF605E56FF5C5F5DFF636566FF696269FF615960FF6A5F67FF676166FF616266FF5F6364FF5E6366FF5F6266FF656167FF6F635FFF82694FFF53360FFF563526FF785E50FF76685CFF6B655EFF676564FF6B686AFF665E65FF70656FFF6D6068FF6B6068FF666267FF626367FF606368FF646268FF69606AFF746360FF836A50FF563912FF543222FF826556FF756558FF6F685FFF686463FF686365FF6C6169FF6D6068FF6F6068FF6B6068FF666267FF626465FF626367FF646367FF696168FF746360FF846A4CFF583A11FF543320FF7F6554FF736656FF6D695EFF666561FF646464FF696267FF6B6068FF6B6068FF696267FF626465FF606465FF606465FF626465FF686267FF72645EFF826A4EFF563912FF4F341FFF7A6752FF6F6756FF6A6A5EFF606661FF5F6564FF646367FF666267FF666267FF626465FF5F6564FF5B6664FF5B6664FF5F6564FF646365FF6F655EFF7D6852FF513818FF4C361DFF766851FF6C6856FF666A5EFF5F6760FF5D6564FF606367FF626367FF626367FF606465FF5B6664FF596763FF596763FF5D6663FF646563FF6D665DFF7D6852FF513818FF4A361DFF766851FF6C6856FF646B5EFF5D6761FF5B6664FF5F6467FF606367FF626367FF606465FF5B6664FF596763FF5B6761FF5D6761FF646561FF70665CFF806A4EFF563914FF4D351FFF786752FF6E6756FF686A5EFF5F6661FF5D6565FF606368FF646268FF646268FF626465FF5F6564FF5D6663FF5F6661FF626661FF686561FF74665AFF846B4BFF5A3A11FF533320FF7E6654FF736658FF6D685FFF646563FF626465FF666268FF696168FF696168FF686267FF646365FF626563FF646561FF686561FF6F6361FF79655AFF866A4CFF583912FF513322FF7F6554FF766656FF74685CFF6D665DFF6D655EFF706361FF726361FF726361FF726360FF6F6460FF6D655EFF6F665DFF72665CFF77645CFF7D6657FF82694FFF513816FFFFF8E7FF463220FF83705BFF7B6952FF7B6650FF7F6950FF7F674FFF7E664EFF816854FF806854FF7E6954FF7E6954FF7E6954FF806953FF836951FF816953FF483520FFFFF4DEFFFFEFDEFFFFF1DEFF442F19FF483117FF5A4121FF4F3412FF563815FF583C1AFF533617FF523618FF50351AFF50351AFF50351AFF503618FF533518FF4E361AFFF9E9D8FFFFFFF4FF"
  Return _ReadImageFromText($tBuffer, $IMAGE, $iWidth, $iHeight)
EndFunc   ;==>_ConvertStringToImage

Func _ReadImageFromText(ByRef $tByte, $sString, $iWidth, $iHeight, $bFileName = False)
  ; Recreate image from text file
  If $bFileName Then $sString = FileRead($sString)
  Local $dData = Binary("0x" & $sString)
  $tByte = DllStructCreate("byte string[" & $iWidth * $iHeight * 4 & "]")
  DllStructSetData($tByte, 1, $dData)
  Return _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $GDIP_PXF32ARGB, $iWidth * 4, DllStructGetPtr($tByte, "string"))
EndFunc   ;==>_ReadImageFromText

Ā 

Edited by CYCho

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...