Esempio n. 1
0
        public int CurrentIndex()
        {
            var pos    = (double)audio.GetPosition().TotalMilliseconds;
            var length = (double)audio.GetLength().TotalMilliseconds;
            var a      = Math.Round(pos / length);

            return((int)Math.Round((pos / length) * signal.Length));
        }
Esempio n. 2
0
 /// <summary>
 /// Возвращает продолжительность трека в секундах
 /// </summary>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public static ulong GetSoundLength(string fileName)
 {
     try {
         var reader   = new WaveFileReader(fileName);
         var contents = new WaveFile();
         contents.maindata          = reader.ReadMainFileHeader();
         contents.maindata.FileName = fileName;
         while (reader.GetPosition() < (long)contents.maindata.dwFileLength)
         {
             var chunkName = reader.GetChunkName();
             if (chunkName == "fmt ")
             {
                 contents.format = reader.ReadFormatHeader();
                 if (reader.GetPosition() + contents.format.dwChunkSize == contents.maindata.dwFileLength)
                 {
                     break;
                 }
             }
             else if (chunkName == "fact")
             {
                 contents.fact = reader.ReadFactHeader();
                 if (reader.GetPosition() + contents.fact.dwChunkSize == contents.maindata.dwFileLength)
                 {
                     break;
                 }
             }
             else if (chunkName.Equals("data"))
             {
                 contents.data = reader.ReadDataHeader();
                 return(Convert.ToUInt64(contents.data.dSecLength));
             }
             else
             {
                 reader.AdvanceToNext();
             }
         }
         if (contents.maindata != null && contents.format != null)
         {
             return(contents.maindata.dwFileLength / contents.format.dwAvgBytesPerSec);
         }
     }
     catch (Exception) {
     }
     return(0);
 }