public void LoadMusic(MusicPack musicPack, string trackName = null) { try { lock (_updateLock) { bool play = _isPlaying; Stop(); _musicPack = musicPack; if (trackName != null) { _musicEntry = _musicPack.FindByName(trackName); } if (trackName == null || _musicEntry.Value == null) { if (_playMode.HasFlag(PlaybackMode.Random)) { _musicEntry = _musicPack.Random(); } else if (_playMode.HasFlag(PlaybackMode.Sequential)) { _musicEntry = _musicPack.Next(); } } if (play && _musicEntry.Value != null) { GameLog.Client.Audio.DebugFormat("called! Trackname: {0}, {1}, playMode={2}", _musicPack.Name, _musicEntry.Value.FileName, _playMode.ToString()); Play(); } } } catch (Exception e) { GameLog.Client.Audio.Error(e); } }
public bool Switch(string trackName) { try { lock (_updateLock) { // TODO: restart track if already played? if (_musicEntry.Value != null && _musicEntry.Value.TrackName.ToUpper().Equals(trackName.ToUpper())) { GameLog.Client.Audio.Debug("Switch = true (1)"); return(true); } var newTrack = _musicPack.FindByName(trackName); if (newTrack.Value == null) { return(false); } bool play = _isPlaying; Stop(); _musicEntry = newTrack; if (play) { Play(); } { GameLog.Client.Audio.DebugFormat("Switch = true (1), _musicPack={0}, _musicEntry={1}", _musicPack.Name, _musicEntry.Key); return(true); } } } catch (Exception e) { GameLog.Client.Audio.Error(e); return(false); } }