Exemplo n.º 1
0
		private void OpenFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
		{

			
            
			TStreamFormat format = player.GetFileFormat(OpenFileDialog1.FileName);
   
			if (LoadMode == 0)
			{
                player.Close();
				if (! (player.OpenFile(OpenFileDialog1.FileName, TStreamFormat.sfAutodetect )))
				{
					MessageBox.Show(player.GetError(), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
				}
			}
			else if (LoadMode == 1)
			{
                player.Close();
				System.IO.FileInfo fInfo = new System.IO.FileInfo(OpenFileDialog1.FileName);
				long numBytes = fInfo.Length;
				System.IO.FileStream fStream = new System.IO.FileStream(OpenFileDialog1.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
				System.IO.BinaryReader br = new System.IO.BinaryReader(fStream);
				byte[] stream_data = null;

				stream_data = br.ReadBytes(System.Convert.ToInt32((int)(numBytes)));
                if (!(player.OpenStream(true, false, ref stream_data, System.Convert.ToUInt32(numBytes), format)))
				{
					MessageBox.Show(player.GetError(), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
				}

				br.Close();
				fStream.Close();
			}
			else if (LoadMode == 2)
			{
                player.Close();
				BufferCounter = 0;

				System.IO.FileInfo fInfo = new System.IO.FileInfo(OpenFileDialog1.FileName);
				uint numBytes = System.Convert.ToUInt32(fInfo.Length);
				if (br != null)
				{
					br.Close();
				}
				if (fStream != null)
				{
					fStream.Close();
				}

				br = null;
				fStream = null;

				fStream = new System.IO.FileStream(OpenFileDialog1.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
				br = new System.IO.BinaryReader(fStream);
				byte[] stream_data = null;
				uint small_chunk = 0;
				small_chunk = System.Convert.ToUInt32(Math.Min(100000, numBytes));
				// read small chunk of data
				stream_data = br.ReadBytes(System.Convert.ToInt32((int)(small_chunk)));
				// open stream
				if (! (player.OpenStream(true, true, ref stream_data, System.Convert.ToUInt32(stream_data.Length), format)))
				{
					MessageBox.Show(player.GetError(), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
				}

				// read more data and push into stream
				stream_data = br.ReadBytes(System.Convert.ToInt32((int)(small_chunk)));
				player.PushDataToStream(ref stream_data, System.Convert.ToUInt32(stream_data.Length));
			}
            else if (LoadMode == 3)
            {
                if (!(player.AddFile(OpenFileDialog1.FileName, TStreamFormat.sfAutodetect)))
                {
                    MessageBox.Show(player.GetError(), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }


            }

			showinfo();
            player.StartPlayback();

		}