Esempio n. 1
0
        } // RefreshTsBuffer

        /// <summary>
        /// Change the Ts File been read from.
        /// </summary>
        /// <param name="fileId">Id number of the new file.</param>
        private void ChangeTsFile(int fileId)
        {
            // Check if there is already a file open.
            if (tsReader != null)
            {
                tsReader.Close();
            }

            // Check if id exists.
            if (fileId >= 0 && fileId < tsFiles.Count)
            {
                int tries = 5; // Try to change the file 5 times before giving up.
                do
                {
                    try
                    {
                        tsReader     = new FileStream(tsFiles[fileId].Location, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        tsReaderFile = tsFiles[fileId];

                        state            = State.Playing; // Set the state so the file is ready to play.
                        tsReaderPosition = 0;             // Reset the reader position to the start.
                        return;
                    }
                    catch (IOException)
                    {
                        // Give it a moment.
                        System.Threading.Thread.Sleep(10);
                    }
                } while (--tries != 0);
            }

            // Something went wrong.
            state = State.InvalidFile;
        } // ChangeTsFile
Esempio n. 2
0
    } // RefreshTsBuffer
    /// <summary>
    /// Change the Ts File been read from.
    /// </summary>
    /// <param name="fileId">Id number of the new file.</param>
    private void ChangeTsFile(int fileId)
    {
      // Check if there is already a file open.
      if (tsReader != null)
      {
        tsReader.Close();
      }

      // Check if id exists.
      if (fileId >= 0 && fileId < tsFiles.Count)
      {
        int tries = 5; // Try to change the file 5 times before giving up.
        do
        {
          try
          {
            tsReader = new FileStream(tsFiles[fileId].Location, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            tsReaderFile = tsFiles[fileId];

            state = State.Playing;                // Set the state so the file is ready to play.
            tsReaderPosition = 0;                 // Reset the reader position to the start.
            return;
          }
          catch (IOException)
          {
            // Give it a moment.
            System.Threading.Thread.Sleep(10);
          }
        } while (--tries != 0);
      }

      // Something went wrong.
      state = State.InvalidFile;
    } // ChangeTsFile