Ejemplo n.º 1
0
        private int GetGapForAya(AyaInfo aya, DynamicGap dynamicGap, AyaInfo nextAya, bool isRevision)
        {
            var    currentAyaFile     = FullAyaFileName(FileNameForAya(aya));
            var    nextAyaFile        = FullAyaFileName(FileNameForAya(nextAya));
            var    currentAyaDuration = GetMediaDuration(currentAyaFile);
            var    nextAyaDuration    = GetMediaDuration(nextAyaFile);
            var    usedDuration       = isRevision ? nextAyaDuration : currentAyaDuration;
            double result;
            int    minGap = 1;

            switch (dynamicGap)
            {
            case DynamicGap.AyaDuration20Percent:
                result = usedDuration * 0.2f;
                break;

            case DynamicGap.AyaDuration40Percent:
                result = usedDuration * 0.4f;
                break;

            case DynamicGap.AyaDuration60Percent:
                result = usedDuration * 0.6f;
                break;

            case DynamicGap.AyaDuration80Percent:
                result = usedDuration * 0.8f;
                break;

            case DynamicGap.AyaDurationOne:
                result = usedDuration * 1f;
                break;

            case DynamicGap.AyaDuration120Percent:
                result = usedDuration * 1.2f;
                break;

            case DynamicGap.AyaDuration140Percent:
                result = usedDuration * 1.4f;
                break;

            case DynamicGap.AyaDuration160Percent:
                result = usedDuration * 1.6f;
                break;

            case DynamicGap.AyaDuration200Percent:
                result = usedDuration * 2f;
                break;

            case DynamicGap.NoGap:
            default:
                result = 0;
                minGap = 0;
                break;
            }

            return(Math.Max(minGap, (int)(result + 0.5)));
        }
Ejemplo n.º 2
0
        public void GenerateJoinedMp3(int juz, DynamicGap dynamicGap, decimal fixedGap)
        {
            Processing = true;

            CleanDirectory(stageDir);
            CleanDirectory(dstDir);

            var navItems = QuranDailyPlanUtil.GetAllNavigationItems(juz);

            var blankOneSecondUrl       = blankOneSecondBaseUrl + reciter.BlankResourceName;
            var blankOneSecondLocalFile = Path.Combine(stageDir, reciter.BlankResourceName);

            using (var blankDownloadWebClient = new WebClient())
            {
                blankDownloadWebClient.DownloadFile(blankOneSecondUrl, blankOneSecondLocalFile);
            }

            int currentDay = 1;

            foreach (var navItem in navItems)
            {
                if (Processing == false)
                {
                    break;
                }

                var outFileName = Path.Combine(dstDir, string.Format("day_{0}_{1}.mp3", currentDay++, navItem.Title));
                var allFiles    = new List <AudioFile>();

                if (Processing == false)
                {
                    break;
                }

                var ayaInfos = GetRangeAyaList(navItem.rangeOfAyas);
                DownloadAyaIfNeeded(ayaInfos[0]);
                foreach (var ayaInfo in ayaInfos)
                {
                    var isLastAya   = ayaInfo.EqualsAya(ayaInfos[ayaInfos.Count - 1]);
                    var nextAyaInfo = isLastAya ? ayaInfo : AyaUtil.GetNextAyaInfoFromCurrent(ayaInfo);

                    if (isLastAya == false)
                    {
                        DownloadAyaIfNeeded(nextAyaInfo);
                    }

                    allFiles.Add(new AudioFile(FullAyaFileName(FileNameForAya(ayaInfo))));
                    var gapSeconds = GetGapForAya(ayaInfo, dynamicGap, nextAyaInfo, navItem.IsRevision) + fixedGap;
                    for (int gapNumber = 0; gapNumber < gapSeconds; gapNumber++)
                    {
                        allFiles.Add(new AudioFile(blankOneSecondLocalFile));

                        Application.DoEvents();
                    }

                    Application.DoEvents();
                }


                Combine(allFiles, outFileName);

                totalProgressBar.Value = Math.Min(100, 100 * currentDay / navItems.Count);
                Application.DoEvents();
            }

            Done();
        }