Home | History | Annotate | Download | only in video
      1 # Copyright 2015 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 
      6 from autotest_lib.client.cros.video import video_player
      7 
      8 
      9 class NativeHtml5Player(video_player.VideoPlayer):
     10     """
     11     Provides an interface to interact with native html5 player in chrome.
     12 
     13     """
     14 
     15 
     16     def inject_source_file(self):
     17         """
     18         Injects the path to the video file under test into the html doc.
     19 
     20 
     21         """
     22         self.tab.ExecuteJavaScript(
     23             'loadVideoSource("%s")' % self.video_src_path)
     24 
     25 
     26     def is_video_ready(self):
     27         """
     28         Determines if a native html5 video is ready by using javascript.
     29 
     30         returns: bool, True if video is ready, else False.
     31 
     32         """
     33         return self.tab.EvaluateJavaScript('canplay()')
     34 
     35 
     36     def play(self):
     37         """
     38         Plays the video.
     39 
     40         """
     41         self.tab.ExecuteJavaScript('play()')
     42 
     43 
     44     def pause(self):
     45         """
     46         Pauses the video.
     47 
     48         """
     49         self.tab.ExecuteJavaScript('pause()')
     50 
     51 
     52     def paused(self):
     53         """
     54         Checks whether video paused.
     55 
     56         """
     57         cmd = "%s.paused" % self.video_id
     58         return self.tab.EvaluateJavaScript(cmd)
     59 
     60 
     61     def ended(self):
     62         """
     63         Checks whether video paused.
     64 
     65         """
     66         cmd = "%s.ended" % self.video_id
     67         return self.tab.EvaluateJavaScript(cmd)
     68 
     69 
     70     def currentTime(self):
     71         """
     72         Returns the current time of the video element.
     73 
     74         """
     75         return self.tab.EvaluateJavaScript('currentTime()')
     76 
     77 
     78     def seek_to(self, t):
     79         """
     80         Seeks a video to a time stamp.
     81 
     82         @param t: timedelta, time value to seek to.
     83 
     84         """
     85         cmd = "%s.currentTime=%.3f" % (self.video_id, t.total_seconds())
     86         self.tab.ExecuteJavaScript(cmd)
     87 
     88 
     89     def has_video_finished_seeking(self):
     90         """
     91         Determines if the video has finished seeking.
     92 
     93         """
     94         return self.tab.EvaluateJavaScript('finishedSeeking()')
     95 
     96 
     97     def wait_for_error(self):
     98         """
     99         Determines if the video has any errors
    100 
    101         """
    102         return self.tab.WaitForJavaScriptExpression('errorDetected();', 30)
    103