<s> '''<STR_LIT>''' <EOL> from kivy . lib . gstplayer import GstPlayer , get_gst_version <EOL> from kivy . core . audio import Sound , SoundLoader <EOL> from kivy . logger import Logger <EOL> from kivy . compat import PY2 <EOL> from kivy . clock import Clock <EOL> from os . path import realpath <EOL> if PY2 : <EOL> from urllib import pathname2url <EOL> else : <EOL> from urllib . request import pathname2url <EOL> Logger . info ( '<STR_LIT>' . format ( <EOL> '<STR_LIT:.>' . join ( map ( str , get_gst_version ( ) ) ) ) ) <EOL> def _on_gstplayer_message ( mtype , message ) : <EOL> if mtype == '<STR_LIT:error>' : <EOL> Logger . error ( '<STR_LIT>' . format ( message ) ) <EOL> elif mtype == '<STR_LIT>' : <EOL> Logger . warning ( '<STR_LIT>' . format ( message ) ) <EOL> elif mtype == '<STR_LIT:info>' : <EOL> Logger . info ( '<STR_LIT>' . format ( message ) ) <EOL> class SoundGstplayer ( Sound ) : <EOL> @ staticmethod <EOL> def extensions ( ) : <EOL> return ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . player = None <EOL> super ( SoundGstplayer , self ) . __init__ ( ** kwargs ) <EOL> def _on_gst_eos_sync ( self ) : <EOL> Clock . schedule_once ( self . _on_gst_eos , <NUM_LIT:0> ) <EOL> def _on_gst_eos ( self , * dt ) : <EOL> if self . loop : <EOL> self . player . stop ( ) <EOL> self . player . play ( ) <EOL> else : <EOL> self . stop ( ) <EOL> def load ( self ) : <EOL> self . unload ( ) <EOL> uri = self . _get_uri ( ) <EOL> self . player = GstPlayer ( uri , None , self . _on_gst_eos_sync , <EOL> _on_gstplayer_message ) <EOL> self . player . load ( ) <EOL> def play ( self ) : <EOL> self . player . set_volume ( self . volume ) <EOL> self . player . play ( ) <EOL> super ( SoundGstplayer , self ) . play ( ) <EOL> def stop ( self ) : <EOL> self . player . stop ( ) <EOL> super ( SoundGstplayer , self ) . stop ( ) <EOL> def unload ( self ) : <EOL> if self . player : <EOL> self . player . unload ( ) <EOL> self . player = None <EOL> def seek ( self , position ) : <EOL> self . player . seek ( position / self . length ) <EOL> def get_pos ( self ) : <EOL> return self . player . get_position ( ) <EOL> def _get_length ( self ) : <EOL> return self . player . get_duration ( ) <EOL> def on_volume ( self , instance , volume ) : <EOL> self . player . set_volume ( volume ) <EOL> def _get_uri ( self ) : <EOL> uri = self . filename <EOL> if not uri : <EOL> return <EOL> if not '<STR_LIT>' in uri : <EOL> uri = '<STR_LIT>' + pathname2url ( realpath ( uri ) ) <EOL> return uri <EOL> SoundLoader . register ( SoundGstplayer ) </s>
