Python实现的视频播放器功能完整示例

  

本文实例讲述了Python实现的视频播放器功能。分享给大家供大家参考,具体如下:

        # - * -编码:utf - 8 - *   #! python3   # ----------------------------------------------------------------------------   # pyglet   #版权Alex Holkner (c) 2006 - 2008   #保留所有权利。   #   #再分配和使用源代码和二进制形式,有或没有   #修改,允许提供下列条件   #得到满足:   #   # *以源代码必须保留的上述版权   #注意,这个列表的条件以及其后的免责声明。   # *以二进制形式重新发布必须保留未经修改的上述版权   #注意,这个列表的条件以及其后的免责声明   #提供的文档和/或其他材料   #分布。   # * pyglet的名称和它的名字   #贡献者可以用来支持或促进产品   #来自这个软件没有特定的书面   #许可。   #   #此软件提供的版权所有者和贡献者   #“是”和任何明示或默示保证,包括但不   #限于适销性和健身的隐含保证   #为特定目的是否认的。在任何事件应当的   #著作权人或贡献者负责任何直接,间接,   #偶然的、特殊的、典型的或间接的损害赔偿(包括   但不限于,替代产品或服务的采购;   #的使用、数据或利润;然而或业务中断)   #引起的任何责任的理论,无论是在合同,严格   #责任或侵权行为(包括疏忽或其他)中出现   #任何方式使用这个软件,即使建议的   #这种损害的可能性。   # ----------------------------------------------------------------------------   “音频和视频播放器与简单的GUI控件。   “‘   __docformat__=『谩?   __version__=' $ Id: $ '   导入系统   从pyglet。gl进口*   进口pyglet   从pyglet。窗口导入关键   def draw_rect (x, y,宽度、高度):   glBegin (GL_LINE_LOOP)   glVertex2f (x, y)   glVertex2f (x +宽度,y)   glVertex2f (x + y +加强筋的宽度和高度)   glVertex2f (x, y +高度)   glEnd ()   类控制(pyglet.event.EventDispatcher):   x=y=0   宽度=身高=10   def __init__(自我、父母):   超级(控制,自我). __init__ ()   自我。父母=父   def hit_test(自我,x, y): #点中控件   返回(自我。x & lt;x & lt;自我。x +自我。宽度和   自我。y & lt;y & lt;自我。y + self.height)   def capture_events(自我):   self.parent.push_handlers(自我)   def release_events(自我):   self.parent.remove_handlers(自我)   类按钮(控制):   带电=False   def画(自我):   如果self.charged:   glColor3f (0,1,0)   draw_rect(自我。x,自我。y,自我。宽度,self.height)   glColor3f (1, 1, 1)   self.draw_label ()   def on_mouse_press(自我,x, y,按钮,修饰符):   self.capture_events ()   自我。带电=True   def on_mouse_drag(自我,x, y, dx, dy,按钮,修饰符):   自我。带电=自我。hit_test (x, y)   def on_mouse_release(自我,x, y,按钮,修饰符):   self.release_events ()   如果自我。hit_test (x, y):   self.dispatch_event (“on_press”)   自我。带电=False   Button.register_event_type (on_press) #注册事件   类TextButton(按钮):   def __init__(自我,* args, * * kwargs):   超级(TextButton,自我)。__init__ (* args, * * kwargs)   自我。_text=pyglet.text。标签(“anchor_x=行摹?anchor_y=爸行摹?   def draw_label(自我):   self._text。x=自我。x +自我。宽/2   self._text。y=自我。y +自我。高度/2   self._text.draw ()   def set_text(自我、文本):   self._text。文本=文本   文本=属性(λ自我:self._text.text,   set_text)   类滑块(控制):   THUMB_WIDTH=6   THUMB_HEIGHT=10   GROOVE_HEIGHT=2   def画(自我):   center_y=自我。y +自我。高度/2   draw_rect(自我。x, center_y——自我。GROOVE_HEIGHT/2,   自我。宽度,self.GROOVE_HEIGHT)   pos=自我。x +自我。*自我价值。宽/(自我。max - self.min)   draw_rect (pos -自我。center_y THUMB_WIDTH/2——自我。THUMB_HEIGHT/2,   自我。THUMB_WIDTH self.THUMB_HEIGHT)   def coordinate_to_value(自我,x): #改变进度   返回浮点数(x - self.x)/自我。宽度*(自我。马克斯- self.min) + self.min   def on_mouse_press(自我,x, y,按钮,修饰符):   值=https://www.yisu.com/zixun/self.coordinate_to_value (x)   self.capture_events ()   self.dispatch_event (“on_begin_scroll”)   自我。dispatch_event (on_change,价值)   def on_mouse_drag(自我,x, y, dx, dy,按钮,修饰符):   值=https://www.yisu.com/zixun/min (max (self.coordinate_to_value (x) self.min), self.max)   自我。dispatch_event (on_change,价值)   def on_mouse_release(自我,x, y,按钮,修饰符):   self.release_events ()   self.dispatch_event (“on_end_scroll”)   Slider.register_event_type (“on_begin_scroll”)   Slider.register_event_type (“on_end_scroll”)   Slider.register_event_type (“on_change”)   类PlayerWindow (pyglet.window.Window):   GUI_WIDTH=400   GUI_HEIGHT=40   GUI_PADDING=4 #按钮间隔   GUI_BUTTON_HEIGHT=16   def __init__(自我,球员):   超级(PlayerWindow,自我)。__init__(标题=懊教宀シ牌鳌?   可见=False,   可调整大小的=True)   自我。球员=球员   self.player.push_handlers(自我)   self.player。eos_action=self.player.EOS_PAUSE   自我。滑块滑块=(自我)   self.slider。x=self.GUI_PADDING #类变量   self.slider。y=自我。null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

Python实现的视频播放器功能完整示例