Need to verify Youtube Video is playing

Asked by mukul bist

Hi,

Is there a way to verify that the youtube or any video is playing apart from verifying play and pause button.

~Mukul

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Eugene S (shragovich) said :
#1

What about taking few screenshots of the area where video is playing and then comparing them? If there is a difference between the 2 screenshots, probably the video is playing..

Revision history for this message
RaiMan (raimund-hocke) said :
#2

@Eugene
Yes this might work, but not always (still phases !?)

This is my solution:
watching the elapsed time display in the control bar and looking for the capture 1.1 seconds before.
Should change while running.

This works for me: (used version 1.0.1)

The lines starting with #dev# I used while developing the script

switchApp("Safari")
top = find("top-left-youtube-logo.png")

# to eval the relative position of the elapsed time display
#dev# highlight(-2)
#dev# r = selectRegion()
#dev# print r, r.x-top.x, r.y-top.y

# elapsed time display
# values might have to be adjusted depending on your top capture
time = Region(top.x+225, top.y+426, 40,20)
# make control bar visible
time.hover()
wait(1)

pause = "button-pause.png"
play = "button-play.png"
button = time.left(30).grow(5)
#dev# button.highlight(2)

# switch to play, if not playing
if button.exists(play, 0):
    button.click()

# show, we started to watch
hover(button.leftAt(20))
while True:
    lastTime = capture(time)
    wait(1.1)
    if (time.exists(Pattern(lastTime).exact(), 0)):
        # probably stopped, show it
        time.highlight(2)
        print "stopped?"
        break

There might be an equivalent solution using observe().

Can you help with this problem?

Provide an answer of your own, or ask mukul bist for more information if necessary.

To post a message you must log in.