Exemplo n.º 1
0
        /// <summary>
        /// Gets called on average every 500ms. This is a console application, so no SynchronizationContext
        /// available. This means this function is called on theNetConnection thread
        /// watch out for that.!
        /// </summary>
        private void NC_OnTick(object sender)
        {
            // feed zplay with data received from netstream
            // Minimum buffer voordat we starten met afspelen
            TStreamStatus status = new TStreamStatus();

            zPlay.GetStatus(ref status);

            // Not playing and buffer has enough data to examine mp3 to start playing
            if (!status.fPlay && zPlayBuffer.UsedBytes >= 8192)
            {
                byte[] tmpBuffer = new byte[8192];
                zPlayBuffer.Read(tmpBuffer, 8192);

                if (!(zPlay.OpenStream(true, true, ref tmpBuffer, 8192, TStreamFormat.sfMp3)))
                {
                    // Got an error with libzplay
                    Console.WriteLine(zPlay.GetError());
                    return;
                }
                // Start playing audio
                zPlay.StartPlayback();
            }
            else if (status.fPlay && zPlayBuffer.UsedBytes > 0)
            {
                int    bufRead   = Convert.ToInt32(zPlayBuffer.UsedBytes);
                byte[] tmpBuffer = new byte[bufRead];
                zPlayBuffer.Read(tmpBuffer, bufRead);

                // Push data into libzplay so it can continue playing audio
                if (!zPlay.PushDataToStream(ref tmpBuffer, Convert.ToUInt32(bufRead)))
                {
                    // Got an error with libzplay
                    Console.WriteLine(zPlay.GetError());
                    return;
                }
            }
        }
Exemplo n.º 2
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();

		}