U
    Peh#                     @   s   d Z dZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZmZmZmZ G dd deZed	krdd
lmZ ddlZeejdkredejd   ed G dd deZe   dS )a  
Video
=====

The :class:`Video` widget is used to display video files and streams.
Depending on your Video core provider, platform, and plugins, you will
be able to play different formats. For example, the pygame video
provider only supports MPEG1 on Linux and OSX. GStreamer is more
versatile, and can read many video containers and codecs such as MKV,
OGV, AVI, MOV, FLV (if the correct gstreamer plugins are installed). Our
:class:`~kivy.core.video.VideoBase` implementation is used under the
hood.

Video loading is asynchronous - many properties are not available until
the video is loaded (when the texture is created)::

    def on_position_change(instance, value):
        print('The position in the video is', value)

    def on_duration_change(instance, value):
        print('The duration of the video is', value)

    video = Video(source='PandaSneezes.avi')
    video.bind(
        position=on_position_change,
        duration=on_duration_change
    )

One can define a preview image which gets displayed until the video is
started/loaded by passing ``preview`` to the constructor::

    video = Video(
        source='PandaSneezes.avi',
        preview='PandaSneezes_preview.png'
    )

One can display the placeholder image when the video stops by reacting on eos::

    def on_eos_change(self, inst, val):
        if val and self.preview:
            self.set_texture_from_resource(self.preview)

    video.bind(eos=on_eos_change)
)Video    )Clock)Image)resource_find)BooleanPropertyNumericPropertyObjectPropertyOptionPropertyStringPropertyc                       s   e Zd ZdZedddZedddZeddd	Z	edZ
edZed
Zed
ZedZei ZdZ fddZdd Zd$ddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Z  ZS )%r   z@Video class. See module documentation for more information.
    NT)Z	allownonestop)playpauser   )optionsF)
deprecated      ?c                    sN   d | _ tt| jf | | d| j d|kr<|d | jd< | jrJ|   d S )Nsourceeos)_videosuperr   __init__Zfbind_trigger_video_loadr   r   )selfkwargs	__class__ 2/tmp/pip-unpacked-wheel-xzebddm3/kivy/uix/video.pyr      s    zVideo.__init__c                 G   s$   | j r| | j  n| | j d S N)previewZset_texture_from_resourcer   r   largsr   r   r   texture_update   s    zVideo.texture_updatec                 C   s&   | j dkrtd| j j||d dS )an  Change the position to a percentage (strictly, a proportion)
           of duration.

        :Parameters:
            `percent`: float or int
                Position to seek as a proportion of the total duration,
                must be between 0-1.
            `precise`: bool, defaults to True
                Precise seeking is slower, but seeks to exact requested
                percent.

        .. warning::
            Calling seek() before the video is loaded has no effect.

        .. versionadded:: 1.2.0

        .. versionchanged:: 1.10.1
            The `precise` keyword argument has been added.
        NzVideo not loaded.)precise)r   	Exceptionseek)r   percentr#   r   r   r   r%      s    
z
Video.seekc                 G   s,   | j }|d kr"t| jd }| _ |  d S )Nr   )_video_load_eventr   Zschedule_once_do_video_load)r   r!   Zevr   r   r   r      s     
zVideo._trigger_video_loadc                 G   s   t d krd S |   | js(d | _d | _nt| j}d|kr>t|}t f d|i| j| _| j| j_| jj| j	| j
| jd | jdks| jr| j  d| _d| _d S )Nz://filename)Zon_loadZon_frameZon_eosr   r           )	CoreVideounloadr   r   texturer   r   volumebind_on_load_on_video_frame_on_eosstater   durationposition)r   r!   r)   r   r   r   r(      s&    


zVideo._do_video_loadc                 C   s   |rdnd}|  ||S )Nr   r   )on_stater   instancevaluer   r   r   on_play   s    zVideo.on_playc                 C   sf   | j s
d S |dkr<| jr*| j   d| j _d| _| j   n&|dkrP| j   n| j   d| j _d S )Nr   r*   Fr   r   )r   r   r   r5   r   r   r7   r   r   r   r6      s    

zVideo.on_statec                 G   s4   | j }|sd S |j| _|j| _|j| _| j  d S r   )r   r4   r5   r-   ZcanvasZ
ask_update)r   r!   videor   r   r   r1      s    zVideo._on_video_framec                 G   s"   | j r| j jdkrd| _d| _d S )NZloopr   T)r   r   r3   r    r   r   r   r2     s    zVideo._on_eosc                 G   s   d| _ | | d S )NT)loadedr1   r    r   r   r   r0     s    zVideo._on_loadc                 C   s   | j r|| j _d S r   )r   r.   r7   r   r   r   	on_volume  s    zVideo.on_volumec                 C   s*   | j r | j   | j   d| _ d| _dS )zYUnload the video. The playback will be stopped.

        .. versionadded:: 1.8.0
        NF)r   r   r,   r<   r   r   r   r   r,     s
    

zVideo.unload)T) __name__
__module____qualname____doc__r
   r   r	   r3   r   r   r   r<   r   r5   r4   r.   r   r   r'   r   r"   r%   r   r(   r:   r6   r1   r2   r0   r=   r,   __classcell__r   r   r   r   r   8   s.   
	

	r   __main__)AppN   zusage: %s file   c                   @   s   e Zd Zdd Zdd ZdS )VideoAppc                 C   s*   t tjd dd| _| jj| jd | jS )NrG   r   )r   r3   )r3   )r   sysargvvr/   replayr>   r   r   r   build%  s    zVideoApp.buildc                 G   s   | j jdkrd| j _d S )Nr   r   )rK   r3   )r   argsr   r   r   rL   *  s    zVideoApp.replayN)r?   r@   rA   rM   rL   r   r   r   r   rH   $  s   rH   )rB   __all__Z
kivy.clockr   Zkivy.uix.imager   Zkivy.core.videor   r+   Zkivy.resourcesr   Zkivy.propertiesr   r   r   r	   r
   r?   Zkivy.apprE   rI   lenrJ   printexitrH   runr   r   r   r   <module>   s    - e

