Jump to content

MediaPlayer Timers Help


Nezoic
 Share

Recommended Posts

Im writing a media player to be extended into another program at a later time. Currently Im working on the control functions and am having problems pausing the timer (which counts for a slide bar as well as elapsed time. Ive noticed SCiTE comes up with a TimerStop function but does this actually exist? If so where?

Ive also checked into a few DLL Functions and found a media timer MMTIMER on MSDN. Im not sure if something like this would be better to use or not. But Im sure the complication would increase quite a bit.

Any suggestions on how to pause this timer, or alternative timers would be a great help.

Here is the code along with two UDFs by Svennie and Simucal, respectively.

media.au3

extprop.au3

#include <GUIConstants.au3>
#include <extprop.au3>
#include <array.au3>
#include <media.au3>
#include <Date.au3>

#Region +++++++++++++++++++  GUI +++++++++++++++++++ 
$Form1 = GUICreate("Musak Bot v1.0", 633, 454, 193, 115)
$lstMedia = GUICtrlCreateListView(" Title                             |Artist                | Album           " & _
                                "| FileName                                                                 " & _
                                "", 24, 16, 441, 344)
$btnBrowse = GUICtrlCreateButton("Browse Folders MP3's", 472, 88, 121, 25, 0)
$btnPlay = GUICtrlCreateButton("Play", 24, 416, 65, 25, 0)
$btnPause = GUICtrlCreateButton("Pause", 96, 416, 65, 25, 0)
$btnBack = GUICtrlCreateButton("<<", 168, 416, 49, 25, 0)
$btnNext = GUICtrlCreateButton(">>", 224, 416, 49, 25, 0)
$btnStop = GUICtrlCreateButton("Stop", 280, 416, 65, 25, 0)
$Slider1 = GUICtrlCreateSlider(16, 376, 449, 17)
$lblDuration = GUICtrlCreateLabel("0", 465, 376, 48, 15)
$lstFolders = GUICtrlCreateListView("", 480, 136, 129, 84, BitOR($LBS_SORT,$WS_BORDER,$WS_VSCROLL))
$gboMediaFolder = GUICtrlCreateGroup("Media Folders", 472, 120, 145, 113)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ++++++++++++++++  End GUI ++++++++++++++++

Global $SearchFolders[1]
Global $PlayingFile = 0
Global $Tick, $TickTotal, $Media, $Secs, $Mins, $Hour, $Time
;#####Test Stuff####
;_ArrayAdd( $SearchFolders, "C:\")
;ImportMp3Data(1)
;###################

                
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnPlay
            if $PlayingFile = 0 Then
                $timer = TimerInit()
                AdlibEnable("Timer", 50)
                SetMedia()
                _MediaPlay($Media)
                $PlayingFile = 1
            EndIf
        Case $btnStop
            _MediaStop($Media)
            $PlayingFile = 0
            AdlibDisable()
            GUICtrlSetData($Slider1, 0)
    
            ;msgbox(0, "", _GetExtProperty($PlaySelectedPath, 7))
        Case $btnPause
            if $PlayingFile = 1 Then
                _MediaPause($Media)
                AdlibDisable()
                $PlayingFile = 2 ;paused
            elseif $PlayingFile = 2 Then
                _MediaResume($Media)
                AdlibEnable("Timer", 50)
                $PlayingFile = 1
            EndIf
                
        Case $btnBrowse
            $newFolder = FileSelectFolder("Choose a folder.", "")
            If $newFolder <> "" Then
                $Pos = _ArraySearch ($SearchFolders, $newFolder)        
                            
                If $pos = -1 Then
                    WinWaitClose("Browes For Folder")
                    GUICtrlCreateListViewItem($newFolder, $lstFolders)
                    _ArrayAdd( $SearchFolders, $newFolder)
                    $SearchFolders[0] = $SearchFolders[0] + 1
                    ImportMp3Data($SearchFolders[0])
                EndIf
            EndIf
    EndSwitch
WEnd

Func ImportMp3Data($Index)
        $CheckRoot = stringright($SearchFolders[$Index], 1)
        if $CheckRoot <> "\" then $SearchFolders[$Index] = $SearchFolders[$Index] & "\"
        
        $search = FileFindFirstFile($SearchFolders[$Index] & "*.mp3")  
        while 1
            $file = FileFindNextFile($search) 
            
            If @error Then ExitLoop
            $Title = _GetExtProperty($searchFolders[$Index] & $file, 10)
            $Artist = _GetExtProperty($searchFolders[$Index] & $file, 16)
            $Album = _GetExtProperty($searchFolders[$Index] & $file, 17)
            GUICtrlCreateListViewItem($Title & "|" & $Artist & "|" & $Album & "|" & $searchFolders[$Index] & $file, $lstMedia)
        WEnd
EndFunc  ;==>ImportMp3Data

Func SetMedia()
    ;Set Slide Bar value and Selected Media
    $PlaySelected = ControlListView("Musak Bot v1.0", "", "SysListView321", "GetSelected")
    $PlaySelectedPath = ControlListView("Musak Bot v1.0", "", "SysListView321", "GetText", $PlaySelected, 3)
    $PlayDuration = _GetExtProperty($PlaySelectedPath, 21)
    $mTime = StringSplit($PlayDuration, ":")
    Local $Seconds = int($mTime[3])
    Local $Minutes = int($mTime[2])
    Local $Hours = int($mTime[1])
    Local $TotalTick = $Seconds + ($Minutes * 60) + ($Hours * 3600)
    GUICtrlSetLimit($Slider1,$TotalTick,0) 

    $Media=_MediaOpen($PlaySelectedPath)
    
EndFunc  ;==>SetMedia


Func Timer()
    _TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs )
    Local $sTime = $Time  ; save current time to be able to test and avoid flicker..
    $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
    $Tick = GuiCtrlRead($Slider1)
    If $sTime <> $Time Then 
        GUICtrlSetData($lblDuration, $Time)
        GUICtrlSetData($Slider1, $Tick + 1)
    EndIf   
EndFunc  ;==>Timer
Link to comment
Share on other sites

Well I found a sort of a work around by adding a global pause timestamp

Case $btnPause
            if $PlayingFile = 1 Then
                _MediaPause($Media)
                ;TimerPause($Timer)
                $PauseTime = $Pausetime + TimerDiff($timer)
                $resume_pause = 1
                AdlibDisable()
                $PlayingFile = 2 ;paused
            elseif $PlayingFile = 2 Then
                _MediaResume($Media)
                $Timer = TimerInit() ; reset init to zero to add pausetime and continue
                AdlibEnable("Timer", 50)
                $PlayingFile = 1
            EndIf

Seems to be fairly accurate however, I think I'll continue searching on the MediaPosition/MMTIME functions and see if i can work up something better. :)

Edited by Nezoic
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...