static void Main(string[] args) { Console.WriteLine("Playing test.mp3. Press Q to quit.\n"); // create ZPlay class ZPlay player = new ZPlay(); // open file if (player.AddFile("1.mp3", TStreamFormat.sfAutodetect) == false) { Console.WriteLine(player.GetError()); return; } // get song length TStreamInfo info = new TStreamInfo(); player.GetStreamInfo(ref info); Console.WriteLine("Length: {0:G}:{1:G}:{2:G}:{3:G}", info.Length.hms.hour, info.Length.hms.minute, info.Length.hms.second, info.Length.hms.millisecond); // start playing player.StartPlayback(); TStreamStatus status = new TStreamStatus(); TStreamTime time = new TStreamTime(); status.fPlay = true; while (status.fPlay) { player.GetPosition(ref time); Console.Write("Pos: {0:G}:{1:G}:{2:G}:{3:G}\r", time.hms.hour, time.hms.minute, time.hms.second, time.hms.millisecond); player.GetStatus(ref status); System.Threading.Thread.Sleep(50); if (Console.KeyAvailable) { var cki = Console.ReadKey(true); if (cki.Key == ConsoleKey.Q) { player.StopPlayback(); } } } }
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(); }