Dart Documentationsimple_audioAudioMusic

AudioMusic class

AudioMusic plays a clip from an omnidirectional AudioSource.

class AudioMusic {
 final AudioManager _manager;
 AudioSource _source;
 AudioSound _sound;
 AudioClip _clip;
 AudioMusic._internal(this._manager, GainNode output) {
   _source = new AudioSource._internal(_manager, 'music', output);
   _source.positional = false;
 }

 Map toJson() {
   Map map = new Map();
   map['clipName'] = _clip._name;
   return map;
 }

 void fromMap(Map map) {
   _clip = _manager.findClip(map['clipName']);
 }

 void _stop() {
   if (_sound != null) {
     _sound.stop();
     _sound = null;
   }
 }

 /** Is the music paused? */
 bool get pause => _sound == null ? false : _sound.pause;
 /** Pause or unpause the music */
 void set pause(bool b) {
   if (_sound != null) {
     _sound.pause = b;
   }
 }

 AudioClip get clip => _clip;

 void set clip(AudioClip clip) {
   _clip = clip;
 }

 /** Play the music clip. The music will loop. */
 void play({loop: true}) {
   _stop();
   _sound = new AudioSound._internal(_source, _clip, loop);
   _sound.play();
 }

 /** Stop the music. */
 void stop() {
   _stop();
 }
}

Properties

AudioClip clip #

AudioClip get clip => _clip;
void set clip(AudioClip clip) {
 _clip = clip;
}

bool get pause #

Is the music paused?

bool get pause => _sound == null ? false : _sound.pause;

void set pause(bool b) #

Pause or unpause the music

void set pause(bool b) {
 if (_sound != null) {
   _sound.pause = b;
 }
}

Methods

void fromMap(Map map) #

void fromMap(Map map) {
 _clip = _manager.findClip(map['clipName']);
}

void play({loop: true}) #

Play the music clip. The music will loop.

void play({loop: true}) {
 _stop();
 _sound = new AudioSound._internal(_source, _clip, loop);
 _sound.play();
}

void stop() #

Stop the music.

void stop() {
 _stop();
}

Map toJson() #

Map toJson() {
 Map map = new Map();
 map['clipName'] = _clip._name;
 return map;
}