# JSDoc: Class: TrackPlayer

# Class: TrackPlayer

## sound.TrackPlayer(options)

#### new TrackPlayer(options)

This class handles the playback of sound tracks.

##### Parameters:

Name | Type | Description
--- | --- | ---

`options`

Object

###### Properties

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`psychoJS` | module:core.PsychoJS |  |  | the PsychoJS instance
`howl` | Object |  |  | the sound object (see https://howlerjs.com/)
`startTime` | number | <optional> | 0 | start of playback (in seconds)
`stopTime` | number | <optional> | -1 | end of playback (in seconds)
`stereo` | boolean | <optional> | true | whether or not to play the sound or track in stereo
`volume` | number | <optional> | 1.0 | volume of the sound (must be between 0 and 1.0)
`loops` | number | <optional> | 0 | how many times to repeat the track or tone after it has played *

Source:
  - sound/TrackPlayer.js, line 12
To Do:
  - stopTime is currently not implemented (tracks will play from startTime to finish)
  - stereo is currently not implemented

### Extends

- SoundPlayer

### Methods

#### (static) accept(sound) → {Object|undefined}

Determine whether this player can play the given sound.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sound` | module:sound.Sound | the sound, which should be the name of an audio resource file

Source:
  - sound/TrackPlayer.js, line 53

##### Returns:

an instance of TrackPlayer that can play the given track or undefined otherwise

Type
  Object | undefined

#### getDuration() → {number}

Get the duration of the sound, in seconds.

Source:
  - sound/TrackPlayer.js, line 90

##### Returns:

the duration of the track, in seconds

Type
  number

#### play(loops, fadeDurationopt)

Start playing the sound.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`loops` | number |  |  | how many times to repeat the track after it has played once. If loops == -1, the track will repeat indefinitely until stopped.
`fadeDuration` | number | <optional> | 17 | how long should the fading in last in ms

Source:
  - sound/TrackPlayer.js, line 160

#### setDuration(duration_s)

Set the duration of the track.

##### Parameters:

Name | Type | Description
--- | --- | ---
`duration_s` | number | the duration of the track in seconds

Source:
  - sound/TrackPlayer.js, line 103

#### setLoops(loops)

Set the number of loops.

##### Parameters:

Name | Type | Description
--- | --- | ---
`loops` | number | how many times to repeat the track after it has played once. If loops == -1, the track will repeat indefinitely until stopped.

Source:
  - sound/TrackPlayer.js, line 137

#### setVolume(volume, muteopt)

Set the volume of the tone.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`volume` | Integer |  |  | the volume of the track (must be between 0 and 1.0)
`mute` | boolean | <optional> | false | whether or not to mute the track

Source:
  - sound/TrackPlayer.js, line 120

#### stop(fadeDurationopt)

Stop playing the sound immediately.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`fadeDuration` | number | <optional> | 17 | how long should the fading out last in ms

Source:
  - sound/TrackPlayer.js, line 201