import pyglet class T(pyglet.window.Window): def __init__(self): super(T, self).__init__() self.player = pyglet.media.Player() # self.player.push_handlers(self.on_eos()) media = pyglet.media.load('1.mp4') self.player.queue(media) self.dur = media.duration print(self.player.source.video_format) print(self.player.source.video_format.width) print(self.player.source.video_format.height) print(media.duration) self.player.play() pyglet.clock.schedule(self.update) # pyglet.clock.schedule_interval(self.update, 1) def update(self, dt): if self.player.time >= self.dur - 0.1 : # 这里减 0.1, 具体根据 dt 定. print('seeking....') self.player.seek(0) self.player.play() print(self.player.time) print('-------------') def on_eos(self): print('end now') def on_draw(self): self.player.get_texture().blit(0,0) T() pyglet.app.run()