Exemplo n.º 1
0
        public AudioControl(bool usesTimer)
        {
            this.player = new ZPlay();

            this.info = new TStreamInfo();
            this.status = new TStreamStatus();
            this.time = new TStreamTime();

            this.timer = usesTimer ? new System.Windows.Forms.Timer() : null;
            if (this.timer != null)
            {
                this.timer.Interval = 100;
                this.timer.Tick += new EventHandler(timer_Tick);
            }
        }
Exemplo n.º 2
0
 private extern static void zplay_GetStatus(uint objptr, ref TStreamStatus pStatus);
Exemplo n.º 3
0
 public void GetStatus(ref TStreamStatus status)
 {
     zplay_GetStatus(objptr, ref status);
 }
Exemplo n.º 4
0
 public void GetStatus(ref TStreamStatus status)
 {
     ZPlay.zplay_GetStatus(this.objptr, ref status);
 }
Exemplo n.º 5
0
 private static extern void zplay_GetStatus(uint objptr, ref TStreamStatus pStatus);
Exemplo n.º 6
0
        public void Run()
        {
            zPlayBuffer = new CircularBlockBuffer();
            zPlay = new ZPlay();
            netConnection = new NetConnection();
            netConnection.OnDisconnect += new NC_OnDisconnect(OnDisconnect);
            netConnection.OnTick += new NC_OnTick(NC_OnTick);
            try
            {
                int result = -1;
                // This is to connect to default vod app
                netConnection.Connect(new ServerLink("rtmp://localhost:1935/vod"), new NC_ResultCallBackConnect((sender, success) =>
                {
                    // Runs in RTMP thread (NOT MainThread!!!)
                    Console.WriteLine("NetConnection.Connect => Success=" + success.ToString());

                    if (success)
                    {
                        result = 1;
                    }
                    else
                    {
                        result = 0;
                    }
                }));

                // Wait until we are connected (needed because we run async)
                while (result == -1)
                {
                    Thread.Sleep(100);
                } //while


                // Succes for connecting to rtmp server
                if (result == 1)
                {
                    NetStream netStream = new NetStream(netConnection);
                    netStream.OnStatus += new NS_OnStatus(NS_OnStatus);
                    netStream.OnAudioPacket += new NC_OnMediaPacket(NC_OnMediaPacket);

                    netStream.WaitForValidStream_ID(4000); // wait max 4 seconds for the netstream to become valid (for real test connect to event)

                    // This is to get and MP3 stream
                    netStream.Play("Comfort_Fit_-_03_-_Sorry.mp3", 0, -1, true);
                }


                Console.WriteLine("Press enter to stop.");
                Console.ReadLine();
            }
            finally
            {
                // Cleanup
                if (netConnection != null)
                {
                    netConnection.Close();
                    netConnection = null;
                }
                if (zPlay != null)
                {
                    TStreamStatus status = new TStreamStatus();
                    zPlay.GetStatus(ref status);
                    if (status.fPlay)
                    {
                        zPlay.StopPlayback();
                    }

                    zPlay.Close();
                    zPlay = null;
                }
                if (zPlayBuffer != null)
                {
                    zPlayBuffer = null;
                }
            }
        }
Exemplo n.º 7
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.º 8
0
        private void Timer1_Tick(object sender, System.EventArgs e)
        {
            TStreamTime pos = new TStreamTime();

            player.GetPosition(ref pos);

            if(ProgressBar1.Maximum > pos.sec)
                ProgressBar1.Value = System.Convert.ToInt32((int)(pos.sec));

            position.Text = System.String.Format("{0,2:G}", pos.hms.hour) + " : " + System.String.Format("{0,2:G}", pos.hms.minute) + " : " + System.String.Format("{0,2:G}", pos.hms.second) + " : " + System.String.Format("{0,3:G}", pos.hms.millisecond);

            TStreamStatus Status = new TStreamStatus();
            player.GetStatus(ref Status);

            statuslabel1.Text = "Eq:" + System.Environment.NewLine + "Fade:" + System.Environment.NewLine + "Echo:" + System.Environment.NewLine + "Bitrate:" + System.Environment.NewLine + "Vocal cut:" + System.Environment.NewLine + "Side cut:";

            statuslabel2.Text = "Loop:" + System.Environment.NewLine + "Reverse:" + System.Environment.NewLine + "Play:" + System.Environment.NewLine + "Pause:" + System.Environment.NewLine + "Channel mix:" + System.Environment.NewLine + "Load:";

            statusvalue1.Text = System.Convert.ToString(Status.fEqualizer) + System.Environment.NewLine + System.Convert.ToString(Status.fSlideVolume) + System.Environment.NewLine + System.Convert.ToString(Status.fEcho) + System.Environment.NewLine + System.Convert.ToString(player.GetBitrate(false)) + System.Environment.NewLine + System.Convert.ToString(Status.fVocalCut) + System.Environment.NewLine + System.Convert.ToString(Status.fSideCut);

            TStreamLoadInfo load = new TStreamLoadInfo();
            player.GetDynamicStreamLoad(ref load);
            statusvalue2.Text = System.Convert.ToString(Status.nLoop) + System.Environment.NewLine + System.Convert.ToString(Status.fReverse) + System.Environment.NewLine + System.Convert.ToString(Status.fPlay) + System.Environment.NewLine + System.Convert.ToString(Status.fPause) + System.Environment.NewLine + System.Convert.ToString(Status.fChannelMix) + System.Environment.NewLine + System.Convert.ToString(load.NumberOfBuffers);

            if (Status.fSlideVolume != false)
            {
                BlockLeft = true;
                BlockRight = true;

                int Left = 0;
                int Right = 0;
                player.GetPlayerVolume(ref Left, ref Right);

                leftplayervolume.Value = 100 - Left;
                rightplayervolume.Value = 100 - Right;

            }

            if (FadeFinished)
            {
                int Left = 0;
                int Right = 0;
                player.GetPlayerVolume(ref Left, ref Right);

                leftplayervolume.Value = 100 - Left;
                rightplayervolume.Value = 100 - Right;
                FadeFinished = false;
            }

            if(NextSong)
            {
                showinfo();
                NextSong = false;
            }
        }