public void Setup(AudioClip song, uint bpm, uint beatOffset) { float beat = 60f / bpm; var music = GameObject.Find("Music").GetComponent <AudioSource>(); music.clip = song; music.time = beat * beatOffset; cues.Add(beat, () => ChangeText("3")); cues.Add(beat * 2, () => ChangeText("2")); cues.Add(beat * 3, () => ChangeText("1")); cues.Add(beat * 4, () => { ChangeText("Go!"); OnFinished(this); }); cues.Add(beat * 6, () => ChangeText("")); }
private void OnEventTypeChanged(object sender, RoutedEventArgs e) { if (e != null) { string ev = e.OriginalSource as string; if (!string.IsNullOrEmpty(ev) && Cues != null) { if (!Cues.Contains(ev)) { Cues.Add(ev); } } } }
/// <summary> /// Parses the given track URL and initializes this instance with it's data. /// </summary> /// <param name="trackUrl">The track URL to create this instance from.</param> private void Parse(string trackUrl) { Uri url = new Uri(trackUrl); string query = url.Query.Substring(1); //omit the question mark string[] items = query.Split('&'); Dictionary <string, string> parameters = items.ToDictionary(item => item.Split('=').First(), item => item.Split('=').Last()); //now go thru the parameters foreach (KeyValuePair <string, string> parameter in parameters) { string decodedKey = HttpUtility.UrlDecode(parameter.Key); string decodedValue = HttpUtility.UrlDecode(parameter.Value); if (decodedKey == "media") { MediaUrl = new Uri(decodedValue); } else if (decodedKey == "title") { Title = decodedValue; } else if (decodedKey == "artist") { Artist = decodedValue; } else if (decodedKey == "album") { Album = decodedValue; } else { double position; if (Double.TryParse(decodedKey, out position)) { Cues.Add(new Cue(position, decodedValue)); } } } }