.. role:: ts-api-decorator

######
Player
######

.. js:module:: Animation
   :noindex:

.. container:: ts-api-section

   .. js:class:: Player



.. container:: api-index-section

   .. rubric:: Properties

   .. rst-class:: api-index-list-item api-kind-property api-parent-kind-class

   * :js:attr:`~Animation.Player.animation`
   * :js:attr:`~Animation.Player.loop`
   * :js:attr:`~Animation.Player.nodeIdOffset`
   * :js:attr:`~Animation.Player.onComplete`
   * :js:attr:`~Animation.Player.speed`
   * :js:attr:`~Animation.Player.LoopIndefinitely`



.. container:: api-index-section

   .. rubric:: Methods

   .. rst-class:: api-index-list-item api-kind-method api-parent-kind-class

   * :js:meth:`~Animation.Player.evaluate`
   * :js:meth:`~Animation.Player.getAnimationTime`
   * :js:meth:`~Animation.Player.getCurrentTime`
   * :js:meth:`~Animation.Player.getState`
   * :js:meth:`~Animation.Player.pause`
   * :js:meth:`~Animation.Player.play`
   * :js:meth:`~Animation.Player.reload`
   * :js:meth:`~Animation.Player.setChannelEnabled`
   * :js:meth:`~Animation.Player.setTime`
   * :js:meth:`~Animation.Player.stop`





------------

Properties
==========

.. container:: ts-api-section

   .. js:attribute:: Player.animation

      :type: Animation

      The animation played by this player



.. container:: ts-api-section

   .. js:attribute:: Player.loop

      :type: number

      The number of times the animation will repeat. Set to [[LoopIndefinitely]] to repeat indefinitely. Default is 0



.. container:: ts-api-section

   .. js:attribute:: Player.nodeIdOffset

      :type: number

      A base offset value which will be applied to all node identifiers in the animation attached to this player.
      This is useful to play an authored animation for a model that has been loaded into the scene after initial startup.
      In this situation the authored node identifiers in the animation may not match up with the runtime node identifiers in the current scene.
      The [[Model.getNodeIdOffset]] function can be used on the loaded model's root node to retrieve the correct offset value.



.. container:: ts-api-section

   .. js:attribute:: Player.onComplete

      :type: null | function

      Callback function to be called when the animation is complete.  Will not be triggered if the player is looping.


      .. js:function:: onComplete()
         :noindex:



         :rtype: void





.. container:: ts-api-section

   .. js:attribute:: Player.speed

      :type: number

      Scale value to be applied to animation time.



.. container:: ts-api-section

   .. js:attribute:: Player.LoopIndefinitely

      :type: -1

      If loop is set to LoopIndefinitely, the animation will play repeatedly.



Methods
=======

.. rst-class:: ts-api-section

evaluate
--------

.. js:method:: Player.evaluate( time[, out])

   :param time: The time at which to evaluate the animation.
   :type time: number
   :param out: :ts-api-decorator:`optional` Storage for the evaluated values. If supplied, this object will be returned instead of a new [[BatchedValues]] object. This allows values gathered from multiple players to be combined into one batch.
   :type out: BatchedValues


   Calculate the values for each channel of the associated [[Animation]]
   at the given time.


   :rtype: BatchedValues

.. rst-class:: ts-api-section

getAnimationTime
----------------

.. js:method:: Player.getAnimationTime()



   Gets the current time in seconds of the entire animation.


   :rtype: number

.. rst-class:: ts-api-section

getCurrentTime
--------------

.. js:method:: Player.getCurrentTime()



   Gets the current time in seconds that the animation has been playing.


   :rtype: number

.. rst-class:: ts-api-section

getState
--------

.. js:method:: Player.getState()



   Gets the current animation state.


   :rtype: PlayerState

.. rst-class:: ts-api-section

pause
-----

.. js:method:: Player.pause()



   Pauses animation playback.


   :rtype: void

.. rst-class:: ts-api-section

play
----

.. js:method:: Player.play()



   Starts playing the animation.


   :rtype: void

.. rst-class:: ts-api-section

reload
------

.. js:method:: Player.reload()



   Updates internal state of animation player.

   Call this method after any part of the underlying animation has been updated.


   :rtype: void

.. rst-class:: ts-api-section

setChannelEnabled
-----------------

.. js:method:: Player.setChannelEnabled( channel, enabled)

   :param channel: a channel from the underlying animation
   :type channel: NodeChannel | CameraChannel
   :param enabled: boolean value indicating whether the channel should be enabled.
   :type enabled: boolean


   Sets the enabled state for a channel in this players animation.
   All channels are enabled by default when a player is created.
   A channel that has been disabled will not have its value interpolated by the system until it is re-enabled


   :rtype: void

.. rst-class:: ts-api-section

setTime
-------

.. js:method:: Player.setTime( time)

   :param time: time in milliseconds
   :type time: number


   Sets the current animation time.


   :rtype: void

.. rst-class:: ts-api-section

stop
----

.. js:method:: Player.stop()



   Stops animation playback and resets the current time to 0.


   :rtype: void

