public AudioRequest(int reciterId, QuranAyah verse, RepeatInfo repeat, int currentRepeatIteration, AudioDownloadAmount audioDownloadAmount) { if (verse == null) throw new ArgumentNullException("verse"); if (verse == null || verse.Surah < 1 || verse.Surah > 114) throw new ArgumentException("verse"); this.Reciter = AudioUtils.GetReciterById(reciterId); this.AudioDownloadAmount = audioDownloadAmount; this.FromAyah = verse; this.CurrentAyah = verse; this.ToAyah = AudioUtils.GetLastAyahToPlay(verse, audioDownloadAmount); if (repeat != null) { this.RepeatInfo = repeat; } else { this.RepeatInfo = new RepeatInfo(); } this.repeatManager = new RepeatManager(this.RepeatInfo, verse, currentRepeatIteration); }
/// <summary> /// AudioRequest from a formatted string /// </summary> /// <param name="formattedString">[local|streaming]://reciterId?amount=AudioDownloadAmount&currentAyah=1:2&fromAyah=1:2&to=2:1&repeat=xxx;currentRepeat=2</param> public AudioRequest(string formattedString) { if (string.IsNullOrEmpty(formattedString)) throw new ArgumentNullException("formattedString"); try { Uri patternAsUri = new Uri(formattedString); if (patternAsUri.Scheme.Equals("local", StringComparison.OrdinalIgnoreCase)) IsStreaming = false; else if (patternAsUri.Scheme.Equals("streaming", StringComparison.OrdinalIgnoreCase)) IsStreaming = true; else throw new ArgumentException("scheme"); this.Reciter = AudioUtils.GetReciterById(int.Parse(patternAsUri.Host)); var splitQueryString = patternAsUri.Query.Split(new char[] { '?', '&' }); int currentRepeatIteration = 0; foreach (var part in splitQueryString) { var splitPart = part.Split('='); if (splitPart[0].Equals("amount", StringComparison.OrdinalIgnoreCase)) { this.AudioDownloadAmount = (AudioDownloadAmount) Enum.Parse(typeof (AudioDownloadAmount), splitPart[1]); } else if (splitPart[0].Equals("currentAyah", StringComparison.OrdinalIgnoreCase)) { this.CurrentAyah = QuranAyah.FromString(splitPart[1]); } else if (splitPart[0].Equals("fromAyah", StringComparison.OrdinalIgnoreCase)) { this.FromAyah = QuranAyah.FromString(splitPart[1]); } else if (splitPart[0].Equals("toAyah", StringComparison.OrdinalIgnoreCase)) { this.ToAyah = QuranAyah.FromString(splitPart[1]); } else if (splitPart[0].Equals("repeat", StringComparison.OrdinalIgnoreCase)) { this.RepeatInfo = RepeatInfo.FromString(splitPart[1]); } else if (splitPart[0].Equals("currentRepeat", StringComparison.OrdinalIgnoreCase)) { int.TryParse(splitPart[1], out currentRepeatIteration); } } if (this.CurrentAyah == null) this.CurrentAyah = this.FromAyah; this.repeatManager = new RepeatManager(this.RepeatInfo, this.FromAyah, currentRepeatIteration); } catch { throw new ArgumentException("formattedString"); } }