Jump to content

Recommended Posts

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

Link to post
Share on other sites
Link to post
Share on other sites

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".

Link to post
Share on other sites

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

 

Link to post
Share on other sites

@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.

Link to post
Share on other sites

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
Link to post
Share on other sites

@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
Link to post
Share on other sites

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

 

Link to post
Share on other sites

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.

Link to post
Share on other sites

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 ?
Link to post
Share on other sites

@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

 

Link to post
Share on other sites

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
Link to post
Share on other sites

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
Link to post
Share on other sites

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
Link to post
Share on other sites

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
Link to post
Share on other sites

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By CYCho
      When sound files have to be played, Sound.au3 UDF comes to our mind immediately. It is simple and easy to use. But WMPlayer.ocx has a lot more features: it can play video clips and flac audio files, which Sound.au3 UDF cannot. Below are quick and dirty comparison of codes utilizing two different methods. Both of them do exactly the same  thing: play back a playlist of audio files, with a simple slider control.

      1. Use of Sound.au3 UDF
      #include <GUIConstants.au3> #include <Sound.au3> #include <Misc.au3> $hGui = GUICreate("Sound.au3", 400, 75, -1, -1) $Label1 = GUICtrlCreateButton("", 0, 0, 400, 20) GUICtrlSetState(-1, $GUI_DISABLE) $Shuttle = GUICtrlCreatePic(StringReplace(@AutoItExe, "autoit3.exe", "\examples\gui\msoobe.jpg"), 0, 0, 20, 20) $Pause = GUICtrlCreateButton("Pause", 160, 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) Local $aPlayList[3] ; Put your own mp3 file paths in this playlist $aPlayList[0] = 2 ; number of files in the playlist $aPlayList[1] = "D:\Music - Classics\Beethoven - Piano Concerto 5 in Eb Major Allegro.mp3" $aPlayList[2] = "D:\Music - Pops\Adele - Hello.mp3" $nFiles = 0 For $i = 1 To $aPlayList[0] If Not FileExists($aPlayList[$i]) Then $nFiles += 1 EndIf Next If $nFiles = $aPlayList[0] Then MsgBox(0, "Sound.au3", "None of the files listed in $aPlayList array exists.", 5) GUIDelete($hGui) Exit EndIf $iPos = 0 ; x coordinate of $Shuttle cntrol in progress bar $hDLL = DllOpen("user32.dll") ; to dectect mouse down on the $Shuttle control $sliderLength = 380 ; in pixels $adlibInterval = 250 ; in milliseconds $nFile = 0 While 1 $nFile += 1 If $nFile > $aPlayList[0] Then $nFile = 1 EndIf $sFullPath = $aPlayList[$nFile] $aSound = _SoundOpen($sFullPath) If $aSound = 0 Then MsgBox(0, "Sound.au3", $sFullPath & @CRLF & @CRLF & "Cannot open this file.", 5) ContinueLoop EndIf _SoundPlay($aSound) $sFile = StringMid($sFullPath, StringInStr($sFullPath, "\", 0, -1)+1) GUICtrlSetData($Label1, $sFile) $mediaLength = _SoundLength($aSound, 2) / 1000 ; in seconds GUICtrlSetData($Length, Int($mediaLength/60) & ":" & StringFormat("%02i", Mod($mediaLength, 60))) AdlibRegister("Slider", $adlibInterval) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _SoundClose($aSound) Exit Case $Pause If GUICtrlRead($Pause) = "Pause" Then _SoundPause($aSound) AdlibUnRegister() GUICtrlSetData($Pause, "Resume") Else _SoundResume($aSound) 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(1) WEnd $mediaPos = Round($iPos/$sliderLength*$mediaLength) $iHour = Int($mediaPos/3600) $iMin = Int(Mod($mediaPos, 3600)/60) $iSec = Mod($mediaPos, 60) _SoundSeek($aSound, $iHour, $iMin, $iSec) _SoundPlay($aSound) AdlibRegister("Slider", $adlibInterval) GUICtrlSetData($Pause, "Pause") EndSwitch If _SoundStatus($aSound) = "stopped" Then ; playing, paused, stopped ExitLoop EndIf WEnd WEnd Func Slider() $mediaPos = _SoundPos($aSound, 2)/1000 $iPos = $mediaPos * $sliderLength / $mediaLength GUICtrlSetPos($Shuttle, $iPos) GUICtrlSetData($Progress, Int($mediaPos/60) & ":" & StringFormat("%02i", Mod($mediaPos, 60))) EndFunc 2. Use of WMPlayer.ocx
      #include <GuiConstants.au3> #include <Misc.au3> $hGui = GUICreate("WMPlayer.OCX", 400, 75, -1, -1) $Label1 = GUICtrlCreateButton("", 0, 0, 400, 20) GUICtrlSetState(-1, $GUI_DISABLE) $Shuttle = GUICtrlCreatePic(StringReplace(@AutoItExe, "autoit3.exe", "examples\gui\msoobe.jpg"), 0, 0, 20, 20) $Pause = GUICtrlCreateButton("Pause", 160, 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) Local $aPlayList[3] ; Put your own mp3 file paths in this playlist $aPlayList[0] = 2 ; number of files in the playlist $aPlayList[1] = "D:\Music - Classics\Beethoven - Piano Concerto 5 in Eb Major Allegro.mp3" $aPlayList[2] = "D:\Music - Pops\Adele - Hello.mp3" $nFiles = 0 For $i = 1 To $aPlayList[0] If Not FileExists($aPlayList[$i]) Then $nFiles += 1 EndIf Next If $nFiles = $aPlayList[0] Then MsgBox(0, "WMPlayer.ocx", "None of the files listed in $aPlayList array exists.", 5) GUIDelete($hGui) Exit EndIf $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 cntrol 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 $nFile = 0 While 1 $nFile += 1 If $nFile > $aPlayList[0] Then $nFile = 1 EndIf $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(5) WEnd If $oPlayer.playState <> 3 Then ContinueLoop EndIf $sFile = StringMid($sFullPath, StringInStr($sFullPath, "\", 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) While 1 $nMsg = GUIGetMsg() Switch $nMsg 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(1) 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 EndIf 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  
    • By therks
      So normally you can use the arrow keys in a GUI to walk through all the controls, not unlike the tab key. But I recently realized that if you put a Pic control in the midst of your normal controls it interrupts the ability to move through the controls (the tab key still works). I really liked the arrow key functionality, and I'm wondering if there's a way to restore that capability without capturing and processing the arrow keys manually, or just moving the Pic creation to a different part of the code.
      I've whipped up a bit of code with some examples:
      #include <GUIConstants.au3> $sPic = StringLeft(@AutoItExe, StringInStr(@AutoItExe, '\', 0, -1)) & '\Examples\GUI\logo4.gif' ; This is the normal behaviour I'd like to keep. GUICreate('Good Example', 250, 150, @DesktopWidth/2 - 250) GUICtrlCreateButton('Button', 50, 0, 200, 30) GUICtrlCreateButton('Button', 50, 30, 200, 30) GUICtrlCreateButton('Button', 50, 60, 200, 30) GUICtrlCreateButton('Button', 50, 90, 200, 30) GUICtrlCreateButton('Button', 50, 120, 200, 30) GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd GUIDelete() ; This is the bad behaviour I'd like to avoid. GUICreate('Example 2', 250, 150, @DesktopWidth/2 - 250) GUICtrlCreatePic($sPic, 0, 0, 50, 30) GUICtrlCreateButton('Button', 50, 0, 200, 30) GUICtrlCreatePic($sPic, 0, 30, 50, 30) GUICtrlCreateButton('Button', 50, 30, 200, 30) GUICtrlCreatePic($sPic, 0, 60, 50, 30) GUICtrlCreateButton('Button', 50, 60, 200, 30) GUICtrlCreatePic($sPic, 0, 90, 50, 30) GUICtrlCreateButton('Button', 50, 90, 200, 30) GUICtrlCreatePic($sPic, 0, 120, 50, 30) GUICtrlCreateButton('Button', 50, 120, 200, 30) GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd GUIDelete() ; This is almost what I want, but notice it doesn't "loop" around like the first example. ; And also having to create the pictures out of sequence with the buttons is not ideal. GUICreate('Example 3', 250, 150, @DesktopWidth/2 - 250) GUICtrlCreateButton('Button', 50, 0, 200, 30) GUICtrlCreateButton('Button', 50, 30, 200, 30) GUICtrlCreateButton('Button', 50, 60, 200, 30) GUICtrlCreateButton('Button', 50, 90, 200, 30) GUICtrlCreateButton('Button', 50, 120, 200, 30) GUICtrlCreatePic($sPic, 0, 0, 50, 30) GUICtrlCreatePic($sPic, 0, 30, 50, 30) GUICtrlCreatePic($sPic, 0, 60, 50, 30) GUICtrlCreatePic($sPic, 0, 90, 50, 30) GUICtrlCreatePic($sPic, 0, 120, 50, 30) GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd GUIDelete() The first GUI that opens demonstrates the behaviour I like. The second GUI demonstrates the problem. The third GUI is almost a solution, but the focus won't wrap around (eg: You can't just hold the down arrow and have the focus loop through the buttons, it sticks at the end). Also creating the pic controls out of sequence with the buttons makes my code harder to read.
    • By Mannyfresh31
      Hello everybody I need help with Opt("GUIOnEventMode",1) 
      I Normally use GUIGetMsg() but I want to learn how GUIOnEventMode works so I created a little test GUI the start button works fine and everything but the problem is that the stop button won't work down below is the code  I made and I'm wondering if someone with experience can explain me and the rest o newbies how it works and also if can post the code already fixed
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> $Stop = False $X=1 $i = 0 Opt("GUIOnEventMode",1) #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 579, 212, 192, 124) Global $Button1 = GUICtrlCreateButton("Stop", 432, 136, 75, 25) Global $Button2 = GUICtrlCreateButton("Start", 96, 136, 75, 25) Global $Progress1 = GUICtrlCreateProgress(24, 40, 526, 49) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUISetOnEvent ($GUI_EVENT_CLOSE, "_exit",$Form1 ) GUICtrlSetOnEvent($Button1,"_Stop") GUICtrlSetOnEvent($Button2,"DecreaseAndIncrement") While 1 sleep(500) WEnd Func _Stop () $Stop = True EndFunc Func _exit () Exit EndFunc Func DecreaseAndIncrement () $Stop = False While $Stop = False $i+=$X ;ConsoleWrite($i & @CRLF) GUICtrlSetData($Progress1,$i) Sleep(80) if $i = 105 Then $X = -1 if $i = 0 Then $X = 1 WEnd EndFunc  
       
      here is the version that works with GUIGetMsg()
       
       
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> $Stop = False $X=1 $i = 0 #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 579, 212, 192, 124) Global $Button1 = GUICtrlCreateButton("Stop", 432, 136, 75, 25) Global $Button2 = GUICtrlCreateButton("Start", 96, 136, 75, 25) Global $Progress1 = GUICtrlCreateProgress(24, 40, 526, 49) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 DecreaseAndIncrement () case $Button1 $Stop = True EndSwitch WEnd Func DecreaseAndIncrement () $Stop = False While $Stop = False $i+=$X ;ConsoleWrite($i & @CRLF) GUICtrlSetData($Progress1,$i) Sleep(80) if $i = 105 Then $X = -1 if $i = 0 Then $X = 1 $nMsg2 = GUIGetMsg() Switch $nMsg2 Case $GUI_EVENT_CLOSE Exit case $Button1 $Stop = True EndSwitch WEnd EndFunc  
       
       
       
       
       
       
    • By CYCho
      #include <GUIConstants.au3>
      #include <WindowsConstants.au3>

      Local $oPlayer, $gVideo, $width, $height
      $oPlayer = ObjCreate("WMPlayer.OCX.7")
      $oPlayer.URL = 'http://www.clubbalcony.com/upload/culture/yong(2).wmv'
      Local $srcFound = True
      Local $time1 = TimerInit()
      While 1
          If $oPlayer.playState() = 3 Then
              $width = $oPlayer.currentMedia.imageSourceWidth
              $height = $oPlayer.currentMedia.imageSourceHeight
              ExitLoop
          EndIf
          If TimerDiff($time1) > 5000 Then
              $srcFound = False
              ExitLoop
          EndIf
          Sleep(50)
      WEnd
      If Not $srcFound Or $width = 0 Then
          $oPlayer.Close()
          Exit
      Else
          $gVideo = GUICreate("Video Control", $width, $height+63, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX), $WS_EX_TOPMOST)
          GUICtrlCreateObj($oPlayer, 0, 0, $width, $height+63)
          $oPlayer.uiMode = "Full"
          $oPlayer.stretchToFit = True
          GUISetState(@SW_SHOW, $gVideo)
      EndIf

      While 1
          $Msg = GUIGetMsg(1)
          Switch $Msg[0]
              Case $GUI_EVENT_CLOSE
                  ExitLoop
              Case $GUI_EVENT_RESIZED
                  ;This is where I want to resize the video image to fit the new window size
          EndSwitch
      WEnd
      $oPlayer.Close()
         
      How should I code the $GUI_EVENT_RESIZED portion to resize the video to fit the resized window? Your help will be greatly appreciated.

       
    • By Skysnake
      Hello
      So I thought it would be cool to use my Gravatar account to display my gravatar in a local GUI.
      I use this code:
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: Skysnake Script Function: Example to download avatar from Gravatar and display locally #ce ---------------------------------------------------------------------------- ; Script Start ; includes #include <Crypt.au3> #include <InetConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> ; declare Global vars Global $md5GraMail = '' ; will store email for Grvatar request request GravatarLogin() GetAvatar() Func GravatarLogin() ; get the email required for downloading the Gravatar Local $sGraMail = InputBox("Get Gravatar", "What is your email registered with Gravatar?", "someone@somewhere.com", "", -1, -1, 0, 0) ; from http://en.gravatar.com/site/implement/hash/ ; make the hash ; Local $dHash = _Crypt_HashData(GUICtrlRead($g_idInputEdit), $g_iAlgorithm) ; Create a hash of the text entered $md5GraMail = _Crypt_HashData(StringLower(StringStripWS($sGraMail, 8)), $CALG_MD5) ; lose the left two '0x' chars and convert to lower case $md5GraMail = StringLower(StringTrimLeft($md5GraMail, 2)) ; Display the result. MsgBox($MB_SYSTEMMODAL, "", $sGraMail & @CRLF & "md5 " & $md5GraMail, 15) EndFunc ;==>GravatarLogin ; example from Help file: /html/functions/InetGet.htm ; Download a file in the background. ; Wait for the download to complete. Func GetAvatar() ; Save the downloaded file to the temporary folder. Local $sFilePath = _WinAPI_GetTempFileName(@TempDir) ; from http://en.gravatar.com/site/implement/images/ ; <img src="https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50" /> ; Download the file in the background with the selected option of 'force a reload from the remote site.' ; the next THREE options are alternatives ; Gravatar sample from here http://en.gravatar.com/site/implement/images/ ; 1 ;Local $hDownload = InetGet("https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50", $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) ; the normal code, should show user avatar ; 2 Local $hDownload = InetGet("https://www.gravatar.com/avatar/" & $md5GraMail & "?d=retro", $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) ; my email hardcoded, downloads, but does not show avatar ; 3 ;Local $hDownload = InetGet("https://www.gravatar.com/avatar/cac637b47c9fecc8aa1dcdf71e7a4cc8", $sFilePath, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND) ; Wait for the download to complete by monitoring when the 2nd index value of InetGetInfo returns True. Do Sleep(250) Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE) ; Retrieve the number of total bytes received and the filesize. Local $iBytesSize = InetGetInfo($hDownload, $INET_DOWNLOADREAD) Local $iFileSize = FileGetSize($sFilePath) ; Close the handle returned by InetGet. InetClose($hDownload) ; Display details about the total number of bytes read and the filesize. MsgBox($MB_SYSTEMMODAL, "", "The total download size: " & $iBytesSize & @CRLF & _ "The total filesize: " & $iFileSize, 1) Local $MyGravatar = @ScriptDir & "\Gravatar.jpg" FileCopy($sFilePath, $MyGravatar) MsgBox(0, "Now showing!", $MyGravatar, 5) ; make gui and show file GUICreate("My Gravatar in a GUI " & $MyGravatar, 350, 300, -1, -1, $WS_SIZEBOX + $WS_SYSMENU) ; will create a dialog box that when displayed is centered Local $idPic = GUICtrlCreatePic($MyGravatar, 50, 50, 80, 80) GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ;FileDelete($MyGravatar) ; Delete the file. FileDelete($sFilePath) EndFunc ;==>GetAvatar Now, here is the issue.
      If I use the example from the Gravatar site, located here:
      http://en.gravatar.com/site/implement/images/
      Then this code  205e460b479e2e5b48aec07710c08d50  downloads this pic   (not me)
      AND it displays correctly.
       
      PROBLEM
      However, If I download my own Gravatar, I see the image in the @Script folder, BUT IT DOES NOT DISPLAY.  The same with the retro image.  To be clear, this image   downloads, but is not displayed.
       
      I guess it has something to do with the format of my gravatar. Or that the display funtion GUICtrlCreatePic() does not like my gravatar.
      I would be grateful if someone would be willing to test this and may offer a suggestion or two... 
      Skysnake
       
×
×
  • Create New...