public void AudioRequestWorksWithStringConstructor() { var request = new AudioRequest("local://0/?amount=Surah&fromAyah=1:2"); Assert.Equal("Minshawi Murattal (gapless)", request.Reciter.Name); Assert.Equal(new QuranAyah(1, 2), request.CurrentAyah); Assert.Equal(AudioDownloadAmount.Surah, request.AudioDownloadAmount); }
public void TestAudioRequestProperties() { var request = new AudioRequest(0, new QuranAyah(1, 2), new RepeatInfo(RepeatAmount.Juz, 2), 0, AudioDownloadAmount.Page); Assert.Equal("Minshawi Murattal (gapless)", request.Reciter.Name); Assert.Equal(new QuranAyah(1, 2), request.CurrentAyah); Assert.Equal(RepeatAmount.Juz, request.RepeatInfo.RepeatAmount); }
public static bool ShouldDownloadGaplessDatabase(AudioRequest request) { if (!request.Reciter.IsGapless) { return false; } string dbPath = request.Reciter.GaplessDatabasePath; if (string.IsNullOrEmpty(dbPath)) { return false; } return !FileUtils.FileExists(dbPath); }
public static bool HaveAllFiles(AudioRequest request) { string baseDirectory = request.Reciter.LocalPath; if (string.IsNullOrEmpty(baseDirectory)) return false; if (!FileUtils.DirectoryExists(baseDirectory)) return false; foreach (var verse in QuranUtils.GetAllAyah(request.FromAyah, request.ToAyah)) { var filename = GetLocalPathForAyah(verse, request.Reciter); if (!FileUtils.FileExists(filename.ToString())) { return false; } } return true; }
public static bool ShouldDownloadBismillah(AudioRequest request) { if (request.Reciter.IsGapless) { return false; } string baseDirectory = request.Reciter.LocalPath; if (!string.IsNullOrEmpty(baseDirectory)) { if (FileUtils.DirectoryExists(baseDirectory)) { string filename = string.Format("1\\1{0}", AudioExtension); if (FileUtils.FileExists(FileUtils.Combine(baseDirectory, filename))) { return false; } } else { FileUtils.MakeDirectory(baseDirectory); } } return DoesRequireBismillah(request); }
public static bool DoesRequireBismillah(AudioRequest request) { QuranAyah minAyah = request.FromAyah; int startSura = minAyah.Surah; int startAyah = minAyah.Ayah; QuranAyah maxAyah = request.ToAyah; int endSura = maxAyah.Surah; int endAyah = maxAyah.Ayah; for (int i = startSura; i <= endSura; i++) { int lastAyah = QuranUtils.GetSurahNumberOfAyah(i); if (i == endSura) { lastAyah = endAyah; } int firstAyah = 1; if (i == startSura) { firstAyah = startAyah; } for (int j = firstAyah; j <= lastAyah; j++) { if (j == 1 && i != Constants.SURA_FIRST && i != Constants.SURA_TAWBA) { return true; } } } return false; }
private async Task<bool> DownloadAudioRequest(AudioRequest request) { bool result = true; // checking if there is aya position file if (!FileUtils.HaveAyaPositionFile()) { result = await DownloadAyahPositionFile(); } // checking if need to download gapless database file if (result && AudioUtils.ShouldDownloadGaplessDatabase(request)) { string url = request.Reciter.GaplessDatabasePath; string destination = request.Reciter.LocalPath; // start the download result = await this.ActiveDownload.Download(url, destination, AppResources.loading_data); } // checking if need to download mp3 if (result && !AudioUtils.HaveAllFiles(request)) { string url = request.Reciter.ServerUrl; string destination = request.Reciter.LocalPath; FileUtils.MakeDirectory(destination); if (request.Reciter.IsGapless) result = await AudioUtils.DownloadGaplessRange(url, destination, request.FromAyah, request.ToAyah); else result = await AudioUtils.DownloadRange(request); } return result; }
private async void AudioProvider_StateChanged(object sender, EventArgs e) { if (QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Stopped || QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Unknown || QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Error) { await Task.Delay(500); // Check if still stopped if (QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Stopped || QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Unknown || QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Error) { AudioPlayerState = AudioState.Stopped; } } else if (QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Paused) { AudioPlayerState = AudioState.Paused; } else if (QuranApp.NativeProvider.AudioProvider.State == AudioPlayerPlayState.Playing) { AudioPlayerState = AudioState.Playing; var track = QuranApp.NativeProvider.AudioProvider.GetTrack(); if (track != null && track.Tag != null) { try { var request = new AudioRequest(track.Tag); var pageNumber = QuranUtils.GetPageFromSurahAyah(request.CurrentAyah); var oldPageIndex = CurrentPageIndex; var newPageIndex = getIndexFromPageNumber(pageNumber); CurrentPageIndex = newPageIndex; if (oldPageIndex != newPageIndex) { await Task.Delay(500); } // If bismillah set to first ayah if (request.CurrentAyah.Ayah == 0) request.CurrentAyah.Ayah = 1; SelectedAyah = request.CurrentAyah; } catch { // Bad track } } } }
public void AudioRequestGotoPreviousReturnBismillah(int expSura, int expAya, int currSura, int currAya) { var request = new AudioRequest(0, new QuranAyah(currSura, currAya), null, 0, AudioDownloadAmount.Page); request.GotoPreviousAyah(); Assert.Equal(new QuranAyah(expSura, expAya), request.CurrentAyah); }
private async void DownloadAndPlayAudioRequest(AudioRequest request) { if (request == null || this.ActiveDownload.IsDownloading) { return; } var result = await DownloadAudioRequest(request); if (!result) { QuranApp.NativeProvider.ShowErrorMessageBox("Something went wrong. Unable to download audio."); } else { var path = AudioUtils.GetLocalPathForAyah(request.CurrentAyah.Ayah == 0 ? new QuranAyah(1, 1) : request.CurrentAyah, request.Reciter); var title = request.CurrentAyah.Ayah == 0 ? "Bismillah" : QuranUtils.GetSurahAyahString(request.CurrentAyah); QuranApp.NativeProvider.AudioProvider.SetTrack(new Uri(path, UriKind.Relative), title, request.Reciter.Name, "Quran", null, request.ToString()); } }
public void AudioRequestGotoNextIncrementsAyah(int expSura, int expAya, int currSura, int currAya) { var request = new AudioRequest(0, new QuranAyah(currSura, currAya), null, 0, AudioDownloadAmount.Page); request.GotoNextAyah(); Assert.Equal(new QuranAyah(expSura, expAya), request.CurrentAyah); }
public void PlayFromAyah(int startSura, int startAyah) { int currentQari = AudioUtils.GetReciterIdByName(SettingsUtils.Get<string>(Constants.PREF_ACTIVE_QARI)); if (currentQari == -1) return; var lookaheadAmount = SettingsUtils.Get<AudioDownloadAmount>(Constants.PREF_DOWNLOAD_AMOUNT); var ayah = new QuranAyah(startSura, startAyah); var request = new AudioRequest(currentQari, ayah, lookaheadAmount); if (SettingsUtils.Get<bool>(Constants.PREF_PREFER_STREAMING)) { PlayStreaming(request); } else { DownloadAndPlayAudioRequest(request); } }
/// <summary> /// Implements the logic to get the previous AudioTrack instance. /// </summary> /// <remarks> /// The AudioTrack URI determines the source, which can be: /// (a) Isolated-storage file (Relative URI, represents path in the isolated storage) /// (b) HTTP URL (absolute URI) /// (c) MediaStreamSource (null) /// </remarks> /// <returns>an instance of AudioTrack, or null if previous track is not allowed</returns> private AudioTrack GetPreviousTrack(AudioTrack currentTrack) { if (currentTrack != null && currentTrack.Tag != null) { var request = new AudioRequest(currentTrack.Tag); if (request.FromAyah != null && request.FromAyah.Equals(request.CurrentAyah)) return null; request.GotoPreviousAyah(); return GetTrackFromRequest(request); } else { return null; } }
private AudioTrack GetTrackFromRequest(AudioRequest request) { var ayah = request.CurrentAyah; var title = ayah.Ayah == 0 ? "Bismillah" : QuranUtils.GetSurahAyahString(ayah.Surah, ayah.Ayah); var path = AudioUtils.GetLocalPathForAyah(ayah.Ayah == 0 ? new QuranAyah(1, 1) : ayah, request.Reciter); using (var isf = IsolatedStorageFile.GetUserStoreForApplication()) { if (!isf.FileExists(path)) return null; else return new AudioTrack(new Uri(path, UriKind.Relative), title, request.Reciter.Name, "Quran", null, request.ToString(), EnabledPlayerControls.All); } }
public void AudioRequestGotoNextRepeatsAyah() { var request = new AudioRequest(0, new QuranAyah(1, 1), new RepeatInfo(RepeatAmount.OneAyah, 1), 0, AudioDownloadAmount.Page); request.GotoNextAyah(); Assert.Equal(new QuranAyah(1, 1), request.CurrentAyah); request.GotoNextAyah(); Assert.Equal(new QuranAyah(1, 2), request.CurrentAyah); }
public void AudioRequestToStringEqualsConstructorWithAllParameters() { var pattern = "local://0/?amount=Juz¤tAyah=1:2&fromAyah=1:2&toAyah=2:2&repeat=Page-2-times¤tRepeat=2"; var request = new AudioRequest(pattern); Assert.Equal(pattern, request.ToString()); }
public void AudioRequestToStringEqualsConstructor() { var pattern = "local://0/?amount=Surah¤tAyah=1:2&fromAyah=2:2¤tRepeat=0"; var request = new AudioRequest(pattern); Assert.Equal(pattern, request.ToString()); }
public static async Task<bool> DownloadRange(AudioRequest request) { var ayahToDownload = QuranUtils.GetAllAyah(request.FromAyah, request.ToAyah); var filesToDownload = new List<string>(); bool result = true; foreach (var ayah in ayahToDownload) { filesToDownload.Add(GetServerPathForAyah(ayah, request.Reciter)); } result = await QuranApp.DetailsViewModel.ActiveDownload.DownloadMultiple(filesToDownload.ToArray(), request.Reciter.LocalPath, AppResources.loading_audio); if (result) { // attempt to download bismillah if it doesn't exist var bismillaFile = GetLocalPathForAyah(new QuranAyah(1, 1), request.Reciter); if (!FileUtils.FileExists(bismillaFile)) { QuranApp.NativeProvider.Log("bismillah doesn't exist, downloading..."); result = await FileUtils.DownloadFileFromWebAsync(GetServerPathForAyah(new QuranAyah(1, 1), request.Reciter), request.Reciter.LocalPath); } } return result; }
private void PlayStreaming(AudioRequest request) { //TODO: download database //TODO: play audio }
private AudioTrack UpdateCurrentTrack(AudioTrack currentTrack) { if (currentTrack != null && currentTrack.Tag != null) { var request = new AudioRequest(currentTrack.Tag); return GetTrackFromRequest(request); } else { return null; } }
public void AudioRequestGotoPreviousDoesntReturnBismillahForTawba() { var request = new AudioRequest(0, new QuranAyah(9, 1), null, 0, AudioDownloadAmount.Page); request.GotoPreviousAyah(); Assert.Equal(new QuranAyah(8, 75), request.CurrentAyah); }