API Documentation - MagmarFire/Enso-Music-Player GitHub Wiki

The following is a list of all available functions and settings Ensō supports.

MusicPlayer

Settings

float CrossFadeTime

(v1.0) The time, in seconds, for a track to completely crossfade to another track.

float CurrentLength [readonly]

(v1.1) The length of the current track, in seconds.

float CurrentTime [readonly]

(v1.1) The play position of the current track, in seconds.

List<MusicTrack> Tracks

(v1.0) The list of loaded music tracks.

MusicTrack PlayingTrack [readonly]

(v1.0) The track that is currently playing.

float StartVolume

(v1.4) The volume the player will be initialized to when the scene loads. Setting this value after the fact will do nothing. To change the volume, use SetVolume().

float Volume [readonly]

(v1.0) The player's volume. Officially made readonly as of v1.4.

Functions

CrossFadeAtPoint(string name, float time[, int timesToLoop = 0])

(v1.1) Crossfades to the track with the given name at the given point on its timeline.

  • name: The name of the track
  • time: The playback time for the track being crossfaded to, in seconds
  • timesToLoop (v1.3): The number of times to loop the track. Set to 0 for endless play.

CrossFadeAtPoint(MusicTrack track, float time[, timesToLoop = 0])

(v1.1) Crossfades to the given track at the given point on its timeline

  • track: The track to crossfade to
  • time: The playback time for the track being crossfaded to, in seconds
  • timesToLoop (v1.3): The number of times to loop the track. Set to 0 for endless play.

void CrossFadeTo(string name[, int timesToLoop = 0])

(v1.0) Crossfades to the track with the given name.

  • name: The name of the track
  • timesToLoop (v1.3): The number of times to loop the track. Set to 0 for endless play.

void CrossFadeTo(MusicTrack track[, int timesToLoop = 0))

(v1.0) Crossfades to the given track.

  • track: The track to crossfade to
  • timesToLoop (v1.3): The number of times to loop the track. Set to 0 for endless play.

void FadeIn()

(v1.0) Fades in the currently-playing track. As of v1.4, this function fades in the audio up to the main player's volume. Does nothing if the audio's already turned up to the player's volume. This function does not mutate the main player's volume. To do so, use SetVolume().

void FadeOut()

(v1.0) Fades out the currently-playing track. As of v1.4, this function fades out the audio all the way to 0. Does nothing if the audio's already turned all the way down. This function does not mutate the main player's volume. To do so, use SetVolume().

void FadeTo(float volume)

(v1.4) Fades the currently-playing track towards a particular volume level. Does nothing if the audio's already turned to this level. This function does not mutate the main player's volume. To do so, use SetVolume().

void FadeInAtPoint(string name, float time[, int timesToLoop = 0])

(v1.1) Fades in the track with the given name starting at the given point on its timeline.

  • name: The name of the track to play. Note that this name is the unique name that the developer assigns each track, not the name of the asset itself.
  • time: The time to fade the track in at, in seconds
  • timesToLoop (v1.3): The number of times to loop the track. Set to 0 for endless play.

void FadeInAtPoint(MusicTrack track, float time[, int timesToLoop = 0])

(v1.1) Fades in the track with the given name starting at the given point on its timeline.

name: The track to play time: The time to fade the track in at, in seconds timesToLoop (v1.3): The number of times to loop the track. Set to 0 for endless play.

MusicTrack GetTrackByName(string name)

(v1.0) Gets the track with the given name. Will throw a KeyNotFoundException if a track with the given name isn't found.

name: The name of the track to retrieve

void Pause()

(v1.1) Pauses the current track

void Unpause()

(v1.1) Unpauses the current track

void Play(string trackName[, int timesToLoop = 0])

(v1.0) Plays a music track.

  • trackName: The name of the track to play. Note that this name is the unique name that the developer assigns each track, not the name of the asset itself.
  • timesToLoop (v1.3): The number of times to loop the track. Set to 0 for endless play.

void Play(MusicTrack track[, int timesToLoop = 0])

(v1.0) Plays a music track.

  • track: The track to play
  • timesToLoop (v1.3): The number of times to loop the track. Set to 0 for endless play.

void PlayAtPoint(MusicTrack track, float time[, int timesToLoop = 0])

(v1.1) Plays the track starting at the given point on its timeline.

  • track: The track to play
  • time: The time to play the track at, in seconds
  • timesToLoop (v1.3): The number of times to loop the track. Set to 0 for endless play.

void Scrub(float time)

(v1.1) Scrubs the currently-playing track to a specific point in its timeline.

time: How far along to scrub the track, in seconds

void ScrubAsPercentage(float percentage)

(v1.1) Scrubs the currently-playing track to a specific point in its timeline.

percentage: How far along to scrub the track, as a percentage of the track's length

void SetVolume(float volume)

(v1.0) Sets the volume of the music player. Does nothing if the player is in the middle of fading.

volume: The volume level, from 0.0 to 1.0

void Stop()

(v1.1) Stops the currently-playing track.

Events

FadeInComplete(MusicPlayerEventArgs event)

(v1.1) Called when a fade in is completed.

FadeOutComplete(MusicPlayerEventArgs event)

(v1.1) Called when a fadeout is completed.

TrackEndOrLoop(MusicPlayerEventArgs event)

(v1.3) Called when a track completes a loop or ends. This is called after TrackEnd or TrackLoop.

TrackEnd(MusicPlayerEventArgs event)

(v1.3) Called when a track ends but not when it loops. This is called before TrackEndOrLoop.

TrackLoop(MusicPlayerEventArgs event)

(v1.3) Called when a track loops but not when it ends. This is called before TrackEndOrLoop.


MusicTrack

Settings

string Name

(v1.0) The name of the track. This is used to uniquely identify the track in the entire playlist. Having tracks with the same name will result in unexpected behavior.

AudioClip Track

(v1.0) The audio asset. Any Unity-supported audio type can be used, but some work better than others.

The following types work as intended:

  • .ogg
  • .aiff / .aif
  • .mp3
  • .wav (v1.2 and later)

The following types are currently untested:

  • .mod
  • .it
  • .s3m
  • .xm

The following types do not work as intended but have workarounds:

  • .wav (v1.1 and below; you must set sampleLoopStart and sampleLoopLength manually)

The following types are not yet supported:

  • None

int LoopPoints.sampleLoopStart

(v1.0) When the loop will start for this track, in samples. Set to 0 to use the defaults defined in the track's metadata.

int LoopPoints.sampleLoopLength

(v1.0) How long a loop will last before the song's playback position returns to sampleLoopStart, in samples. Set to 0 to use the defaults defined in the track's metadata.

string LoopPoints.RelativeFilePath

(v1.4.1) The path to the audio clip, relative to your project's Asset folder. For example, if you have a folder in the root of your project called Music and your audio clip is named test.ogg, you'd set this as Music/test.ogg. If you're setting all the information yourself instead of using the original audio file's metadata, and if you're not compensating for frequency changes, you don't need to set this.

bool LoopPoints.compensateForFrequency

(v1.2) If this is true, Ensō will automatically adjust the set loop points for any change in frequency that may have happened when importing the audio clip into Unity. Set it to false if you want to calculate the compensation yourself and to use the loop points as written.

int Channels [readonly]

(v1.2) The number of audio channels the track has.

int Frequency [readonly]

(v1.2) The new frequency of the track. This may be different than the track's original frequency before it was imported.

float FrequencyRatio [readonly]

(v1.2) The ratio between the new, Unity-assigned frequency and the track's original frequency.

int LengthInSamples [readonly]

(v1.1) The sum of the lengths of the intro clip and loop clip, in samples.

float LengthInSeconds [readonly]

(v1.1) The sum of the lengths of the intro clip and loop clip, in seconds.

Functions

float SamplesToSeconds(int samples)

(v1.2) Converts the inputted time in samples to its equivalent in seconds.

samples: The time in samples to convert

int SecondsToSamples(float seconds)

(v1.2) Converts the inputted time in seconds to its equivalent time in samples.

seconds: The time in seconds to convert

int TimeToSamples(float time) [deprecated]

(v1.1) Converts the inputted time to its equivalent time in samples.

time: The time along the track's timeline, in seconds

Note: This function is deprecated as of v1.2. Please use SecondsToSamples() instead.