Beispiel #1
0
    // C'est ici qu'il faudra faire notre travail.
    public void ThreadLoop()
    {
        IPHostEntry      ipHostInfo    = Dns.GetHostEntry("vps39194.ovh.net");
        IPAddress        ipAddress     = ipHostInfo.AddressList[0];
        IPEndPoint       remoteEP      = new IPEndPoint(ipAddress, 6664);
        BackgroundPlayer player_thread = null;
        // Create a TCP/IP  socket.
        Socket reader = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

        reader.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
        reader.Connect(remoteEP);

        // serverConnectionOutupt = "Connecté au serveur";
        //cc.Text = "toto";
        front_end.SetServerConnectionText("Connecté au serveur");

        while (Thread.CurrentThread.IsAlive)
        {
            byte[] buffer = new byte[1024];
            reader.Receive(buffer);
            string sPlaylist = Encoding.Default.GetString(buffer);
            Debug.WriteLine("sPlaylist = " + sPlaylist);
            JArray oPlaylist = JArray.Parse(sPlaylist);
            Debug.WriteLine("oPlaylist = " + oPlaylist);

            if (player_thread != null)
            {
                player_thread.interrupt_play = true;
            }

            player_thread = new BackgroundPlayer("sounds/", oPlaylist, front_end);
        }
    }
Beispiel #2
0
 private void TrimForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (BackgroundPlayer.IsBusy)
     {
         BackgroundPlayer.CancelAsync();
     }
 }
Beispiel #3
0
        private void BackgroundPlayer_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            object[] arguments = e.Argument as object[];

            WaveStream WaveFloat = (WaveStream)arguments[0];
            int        LeftPos   = Conversions.ToInteger(arguments[1]);
            int        RightPos  = Conversions.ToInteger(arguments[2]);
            var        bytes     = new byte[RightPos - LeftPos + 1];

            WaveFloat.Position = LeftPos;
            WaveFloat.Read(bytes, 0, RightPos - LeftPos);
            WaveFloat = new RawSourceWaveStream(new MemoryStream(bytes), WaveFloat.WaveFormat);
            // WaveFloat.PadWithZeroes = False

            using (var output = new WaveOutEvent())
            {
                output.Init(WaveFloat);
                output.Play();
                while (output.PlaybackState == PlaybackState.Playing & !BackgroundPlayer.CancellationPending)
                {
                    Thread.Sleep(45);
                    BackgroundPlayer.ReportProgress((int)(output.GetPosition() / (WaveFloat.WaveFormat.BitsPerSample / 8d)));
                }
            }
        }
Beispiel #4
0
 private void PlayButton_Click(object sender, EventArgs e)
 {
     if (BackgroundPlayer.IsBusy == false)
     {
         BackgroundPlayer.RunWorkerAsync(new object[3] {
             AdvWaveViewer1.WaveStream, AdvWaveViewer1.leftpos, AdvWaveViewer1.rightpos
         });
         PlayButton.Text = "Stop";
         DisableInterface();
         PlayButton.Enabled = true;
     }
     else
     {
         BackgroundPlayer.CancelAsync();
         PlayButton.Text = "Play";
     }
 }
Beispiel #5
0
        private void BackgroundPlayer_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            WaveStream WaveFloat = (e.Argument as object[])[0] as WaveStream;
            int        LeftPos   = (int)(e.Argument as object[])[1];
            int        RightPos  = (int)(e.Argument as object[])[2];

            byte[] bytes = new byte[(RightPos - LeftPos) + 1];

            WaveFloat.Position = LeftPos;
            WaveFloat.Read(bytes, 0, (RightPos - LeftPos));

            WaveFloat = new RawSourceWaveStream(new MemoryStream(bytes), WaveFloat.WaveFormat);
            //WaveFloat.PadWithZeroes = False

            using (var output = new WaveOutEvent()) {
                output.Init(WaveFloat);
                output.Play();
                while (output.PlaybackState == PlaybackState.Playing & !BackgroundPlayer.CancellationPending)
                {
                    Thread.Sleep(45);
                    BackgroundPlayer.ReportProgress((int)output.GetPosition() / (WaveFloat.WaveFormat.BitsPerSample / 8));
                }
            }
        }