public Question CreateNewQuestion() { var subject = (Subject)_random.Next(Constants.SUBJECTS_COUNT); Dictionary<string, TagLib.File> rawOptions = new Dictionary<string, TagLib.File>(); while (rawOptions.Count < Constants.OPTIONS_COUNT) { var file = _files[_random.Next(_files.Count)]; var option = Reencode(Constants.ProjectionBySubject[subject](file.Tag)); if (rawOptions.ContainsKey(option)) continue; rawOptions[option] = file; } var options = rawOptions.Select(kvp => new Option() { Title = kvp.Key, File=kvp.Value, IsCorrect = false }).ToList(); var title = Constants.QuestionsBySubject[subject]; int answer = _random.Next(Constants.OPTIONS_COUNT); options[answer].IsCorrect = true; var musicFile = new MusicFile(options[answer].File); return new Question() { Title=title, Options=options, File = musicFile }; }
public Question CreateNewQuestion() { var subject = (Subject)_random.Next(Constants.SUBJECTS_COUNT); Dictionary <string, TagLib.File> rawOptions = new Dictionary <string, TagLib.File>(); while (rawOptions.Count < Constants.OPTIONS_COUNT) { var file = _files[_random.Next(_files.Count)]; var option = Reencode(Constants.ProjectionBySubject[subject](file.Tag)); if (rawOptions.ContainsKey(option)) { continue; } rawOptions[option] = file; } var options = rawOptions.Select(kvp => new Option() { Title = kvp.Key, File = kvp.Value, IsCorrect = false }).ToList(); var title = Constants.QuestionsBySubject[subject]; int answer = _random.Next(Constants.OPTIONS_COUNT); options[answer].IsCorrect = true; var musicFile = new MusicFile(options[answer].File); return(new Question() { Title = title, Options = options, File = musicFile }); }
internal static void SetStartPosition(MusicFile file) { double cueIn = 0, cueOut = 0; int handle = Bass.BASS_StreamCreateFile(file.File.Name, 0, 0, BASSFlag.BASS_STREAM_DECODE); if (handle == 0) { throw new ApplicationException(string.Format("Could not open stream for file {0}.", file.File.Name)); } try { Utils.DetectCuePoints(handle, 1, ref cueIn, ref cueOut, -24, -24, 0); file.CueIn = cueIn; file.CueOut = cueOut; } catch { Debug.WriteLine(string.Format("Warning: Could not find cues for file {0}.", file.File.Name)); file.CueIn = 0; file.CueOut = Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(handle, Bass.BASS_ChannelGetLength(handle)); } double position = _random.NextDouble() * (cueOut - cueIn); file.StartPosition = position; Bass.BASS_StreamFree(handle); }
public void Play(MusicFile file) { if (_currentStream != 0) Stop(); _currentStream = Bass.BASS_StreamCreateFile(file.File.Name, 0, 0, BASSFlag.BASS_DEFAULT); if (_currentStream == 0) throw new ApplicationException(string.Format("Could not play file {0}.", file.File.Name)); Bass.BASS_ChannelSetPosition(_currentStream, file.StartPosition); Bass.BASS_ChannelPlay(_currentStream, false); }
public void Play(MusicFile file) { if (_currentStream != 0) { Stop(); } _currentStream = Bass.BASS_StreamCreateFile(file.File.Name, 0, 0, BASSFlag.BASS_DEFAULT); if (_currentStream == 0) { throw new ApplicationException(string.Format("Could not play file {0}.", file.File.Name)); } Bass.BASS_ChannelSetPosition(_currentStream, file.StartPosition); Bass.BASS_ChannelPlay(_currentStream, false); }
internal static void SetStartPosition(MusicFile file) { double cueIn = 0, cueOut = 0; int handle = Bass.BASS_StreamCreateFile(file.File.Name, 0, 0, BASSFlag.BASS_STREAM_DECODE); if (handle == 0) throw new ApplicationException(string.Format("Could not open stream for file {0}.", file.File.Name)); try { Utils.DetectCuePoints(handle, 1, ref cueIn, ref cueOut, -24, -24, 0); file.CueIn = cueIn; file.CueOut = cueOut; } catch { Debug.WriteLine(string.Format("Warning: Could not find cues for file {0}.", file.File.Name)); file.CueIn = 0; file.CueOut = Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(handle, Bass.BASS_ChannelGetLength(handle)); } double position = _random.NextDouble() * (cueOut - cueIn); file.StartPosition = position; Bass.BASS_StreamFree(handle); }