コード例 #1
0
        /// <summary>
        /// Stops playing audio, disconnects any netStream connections and as
        /// last disconnects the NetConnection
        /// </summary>
        protected virtual void MPThread_Disconnect()
        {
            lock (lockVAR)
            {
                // turn it off
                dtLastAutoReconnect = DateTime.MaxValue; // turns autoreconnect off
                netConnectionReady = false;

                foreach (NetStreamHelper nsh in netStreams)
                {
                    nsh.Close();
                } //foreach
                netStreams.Clear();

                if (netConnection != null)
                {
                    NetConnection tmpNC = netConnection;
                    // protect anaginst recusve callback
                    netConnection = null;
                    
                    // this should fire an ondisconnectserver event
                    tmpNC.Close();                    
                }
            } //lock
        }
コード例 #2
0
        /// <summary>
        /// Connect to RTMP server using RTMPServerLink settings
        /// When "Mediaplayer" is connected the "OnServerConnect" event will be fired
        /// 
        /// WARNING if there are changes don't fortget to do this for eMuziek en MuziekwebLusiter 
        /// classes also (have roughly same implementatino with added securirty calls)
        /// </summary>
        protected virtual void MPThread_Connect()
        {
            lastConnectFailed = false;

            MP_OnStateChangeMediaplayer onStateChangeMediaplayer = null;
            lock (lockVAR)
            {
                onStateChangeMediaplayer = OnStateChangeMediaplayer;
                mediaplayerState = MediaplayerState.Connecting;
                dtLastAutoReconnect = DateTime.Now;
            }
            DoEvent_MP_OnStateChangeMediaplayer(onStateChangeMediaplayer, this, mediaplayerState);

            // possible button state changed
            DoEvent_MP_OnControleButtonStateChange(OnControleButtonStateChange, this);

            netConnectionReady = false;
            netStreams.Clear();
            if (netConnection != null)
            {
                netConnection.Close();
                netConnection = null;
            }

            // Important to only do this here. In derived classes this function is overriden to add
            // securtity calls
            netConnection = new NetConnection(null); // force event over NetConnection thread (we will managed them in this class ourself)
            netConnection.OnDisconnect += new NC_OnDisconnect(NC_OnDisconnect);
            netConnection.Connect(rtmpServerLink, NC_OnConnect);
        }
コード例 #3
0
        public NetStream(NetConnection connection, bool autoConnect = true)
        {
            InitVars();
            netConnection = connection;

            if (autoConnect)
            {
                NetStreamInitialize();
            }
        }
コード例 #4
0
        public virtual void Close()
        {
            // Do something
            if (netConnection != null)
            {
                if (stream_id > 0)
                {
                    netConnection.DeleteStream(stream_id);
                }
                netConnection.UnRegisterNetStream(this);
            }

            // Now reset stream_id (we are nog connected anymore to a NetConnection)
            stream_id = -1;
            // probaly already erased by UnRegisterNetStream
            netConnection = null;
            InitVars();
        }
コード例 #5
0
ファイル: TestRun.cs プロジェクト: parta0207/rtmp-mediaplayer
        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;
                }
            }
        }