<s> '''<STR_LIT>''' <EOL> __all__ = ( '<STR_LIT>' , ) <EOL> from kivy . core . audio import Sound , SoundLoader <EOL> from pyobjus import autoclass <EOL> from pyobjus . dylib_manager import load_framework , INCLUDE <EOL> load_framework ( INCLUDE . AVFoundation ) <EOL> AVAudioPlayer = autoclass ( "<STR_LIT>" ) <EOL> NSURL = autoclass ( "<STR_LIT>" ) <EOL> NSString = autoclass ( "<STR_LIT>" ) <EOL> class SoundAvplayer ( Sound ) : <EOL> @ staticmethod <EOL> def extensions ( ) : <EOL> return ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . _avplayer = None <EOL> super ( SoundAvplayer , self ) . __init__ ( ** kwargs ) <EOL> def load ( self ) : <EOL> self . unload ( ) <EOL> fn = NSString . alloc ( ) . initWithUTF8String_ ( self . filename ) <EOL> url = NSURL . alloc ( ) . initFileURLWithPath_ ( fn ) <EOL> self . _avplayer = AVAudioPlayer . alloc ( ) . initWithContentsOfURL_error_ ( <EOL> url , None ) <EOL> def unload ( self ) : <EOL> self . stop ( ) <EOL> self . _avplayer = None <EOL> def play ( self ) : <EOL> if not self . _avplayer : <EOL> return <EOL> self . _avplayer . play ( ) <EOL> super ( SoundAvplayer , self ) . play ( ) <EOL> def stop ( self ) : <EOL> if not self . _avplayer : <EOL> return <EOL> self . _avplayer . stop ( ) <EOL> super ( SoundAvplayer , self ) . stop ( ) <EOL> def seek ( self , position ) : <EOL> if not self . _avplayer : <EOL> return <EOL> self . _avplayer . playAtTime_ ( float ( position ) ) <EOL> def get_pos ( self ) : <EOL> if self . _avplayer : <EOL> return self . _avplayer . currentTime <EOL> return super ( SoundAvplayer , self ) . get_pos ( ) <EOL> def on_volume ( self , instance , volume ) : <EOL> if self . _avplayer : <EOL> self . _avplayer . volume = float ( volume ) <EOL> def _get_length ( self ) : <EOL> if self . _avplayer : <EOL> return self . _avplayer . duration <EOL> return super ( SoundAvplayer , self ) . _get_length ( ) <EOL> SoundLoader . register ( SoundAvplayer ) </s>
