<s> '''<STR_LIT>''' <EOL> __all__ = ( '<STR_LIT>' , ) <EOL> from kivy . clock import Clock <EOL> from kivy . uix . image import Image <EOL> from kivy . core . video import Video as CoreVideo <EOL> from kivy . resources import resource_find <EOL> from kivy . properties import ( BooleanProperty , NumericProperty , ObjectProperty , <EOL> OptionProperty ) <EOL> class Video ( Image ) : <EOL> '''<STR_LIT>''' <EOL> state = OptionProperty ( '<STR_LIT>' , options = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> '''<STR_LIT>''' <EOL> play = BooleanProperty ( False ) <EOL> '''<STR_LIT>''' <EOL> eos = BooleanProperty ( False ) <EOL> '''<STR_LIT>''' <EOL> loaded = BooleanProperty ( False ) <EOL> '''<STR_LIT>''' <EOL> position = NumericProperty ( - <NUM_LIT:1> ) <EOL> '''<STR_LIT>''' <EOL> duration = NumericProperty ( - <NUM_LIT:1> ) <EOL> '''<STR_LIT>''' <EOL> volume = NumericProperty ( <NUM_LIT:1.> ) <EOL> '''<STR_LIT>''' <EOL> options = ObjectProperty ( { } ) <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . _video = None <EOL> super ( Video , self ) . __init__ ( ** kwargs ) <EOL> self . fbind ( '<STR_LIT:source>' , self . _trigger_video_load ) <EOL> if "<STR_LIT>" in kwargs : <EOL> self . options [ "<STR_LIT>" ] = kwargs [ "<STR_LIT>" ] <EOL> if self . source : <EOL> self . _trigger_video_load ( ) <EOL> def seek ( self , percent ) : <EOL> '''<STR_LIT>''' <EOL> if self . _video is None : <EOL> raise Exception ( '<STR_LIT>' ) <EOL> self . _video . seek ( percent ) <EOL> def _trigger_video_load ( self , * largs ) : <EOL> Clock . unschedule ( self . _do_video_load ) <EOL> Clock . schedule_once ( self . _do_video_load , - <NUM_LIT:1> ) <EOL> def _do_video_load ( self , * largs ) : <EOL> if CoreVideo is None : <EOL> return <EOL> if self . _video : <EOL> self . _video . stop ( ) <EOL> if not self . source : <EOL> self . _video = None <EOL> self . texture = None <EOL> else : <EOL> filename = self . source <EOL> if not '<STR_LIT>' in filename : <EOL> filename = resource_find ( filename ) <EOL> self . _video = CoreVideo ( filename = filename , ** self . options ) <EOL> self . _video . volume = self . volume <EOL> self . _video . bind ( on_load = self . _on_load , <EOL> on_frame = self . _on_video_frame , <EOL> on_eos = self . _on_eos ) <EOL> if self . state == '<STR_LIT>' or self . play : <EOL> self . _video . play ( ) <EOL> self . duration = <NUM_LIT:1.> <EOL> self . position = <NUM_LIT:0.> <EOL> def on_play ( self , instance , value ) : <EOL> value = '<STR_LIT>' if value else '<STR_LIT>' <EOL> return self . on_state ( instance , value ) <EOL> def on_state ( self , instance , value ) : <EOL> if not self . _video : <EOL> return <EOL> if value == '<STR_LIT>' : <EOL> if self . eos : <EOL> self . _video . stop ( ) <EOL> self . _video . position = <NUM_LIT:0.> <EOL> self . _video . eos = False <EOL> self . eos = False <EOL> self . _video . play ( ) <EOL> elif value == '<STR_LIT>' : <EOL> self . _video . pause ( ) <EOL> else : <EOL> self . _video . stop ( ) <EOL> self . _video . position = <NUM_LIT:0> <EOL> self . _video . eos = False <EOL> def _on_video_frame ( self , * largs ) : <EOL> video = self . _video <EOL> if not video : <EOL> return <EOL> self . duration = video . duration <EOL> self . position = video . position <EOL> self . texture = video . texture <EOL> self . canvas . ask_update ( ) <EOL> def _on_eos ( self , * largs ) : <EOL> if self . _video . eos != '<STR_LIT>' : <EOL> self . state = '<STR_LIT>' <EOL> self . eos = True <EOL> def _on_load ( self , * largs ) : <EOL> self . loaded = True <EOL> self . _on_video_frame ( largs ) <EOL> def on_volume ( self , instance , value ) : <EOL> if self . _video : <EOL> self . _video . volume = value <EOL> def unload ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . _video : <EOL> self . _video . stop ( ) <EOL> self . _video . unload ( ) <EOL> self . _video = None <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from kivy . app import App <EOL> import sys <EOL> if len ( sys . argv ) != <NUM_LIT:2> : <EOL> print ( "<STR_LIT>" % sys . argv [ <NUM_LIT:0> ] ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> class VideoApp ( App ) : <EOL> def build ( self ) : <EOL> self . v = Video ( source = sys . argv [ <NUM_LIT:1> ] , state = '<STR_LIT>' ) <EOL> self . v . bind ( state = self . replay ) <EOL> return self . v <EOL> def replay ( self , * args ) : <EOL> if self . v . state == '<STR_LIT>' : <EOL> self . v . state = '<STR_LIT>' <EOL> VideoApp ( ) . run ( ) </s>
