protected void RendererRecycledConnectionSinkEx(AVRenderer sender, AVConnection connection, object Handle)
 {
     TreeNode node = NodeTagSearch(rendererRootNode,connection);
     if (node != null)
     {
         // Connection was recycled, update it
         node.Text = connection.ConnectionID.ToString() + " - " + connection.CurrentState.ToString();
         if (listViewSelectedObject == connection) SetListInfo(connection);
     }
 }
        protected void RendererCreateConnectionSinkEx(AVRenderer sender, AVConnection connection, object Handle)
        {
            TreeNode node = NodeTagSearch(rendererRootNode,connection);
            if (node != null)
            {
                // Connection was recycled, update it
                node.Text = connection.ConnectionID.ToString() + " - " + connection.CurrentState.ToString();
                if (listViewSelectedObject == connection) SetListInfo(connection);
            }
            else
            {
                // New connection, lets add it to the renderer
                node = NodeTagSearch(rendererRootNode,sender);
                if (node == null) MessageBox.Show(this,"Got new connection on unknown renderer");
                TreeNode varNode = new TreeNode(connection.ConnectionID.ToString() + " - " + connection.CurrentState.ToString(),1,1);
                varNode.Tag = connection;
                node.Nodes.Add(varNode);

                connection.OnVolume += new AVConnection.VolumeChangedHandler(VolumeChangedHandlerSink);
                connection.OnPlayStateChanged += new AVConnection.PlayStateChangedHandler(PlayStateChangedHandlerSink);
                connection.OnMute += new AVConnection.MuteStateChangedHandler(MuteStateChangedHandlerSink);
                connection.OnPositionChanged += new AVConnection.PositionChangedHandler(PositionChangedHandlerSink);
                connection.OnMediaResourceChanged += new AVConnection.MediaResourceChangedHandler(MediaResourceChangedHandlerSink);
                connection.OnRemoved += new AVConnection.RendererHandler(RemovedConnectionHandlerSink);
                connection.OnTrackChanged += new AVConnection.CurrentTrackChangedHandler(TrackChangedSink);
                connection.OnCurrentMetaDataChanged += new AVConnection.CurrentMetaDataChangedHandler(MetaDataSink);
            }
        }
        protected void ConnectionInfoSink(CpConnectionManager sender, System.Int32 ConnectionID, System.Int32 RcsID, System.Int32 AVTransportID, System.String ProtocolInfo, System.String PeerConnectionManager, System.Int32 PeerConnectionID, CpConnectionManager.Enum_A_ARG_TYPE_Direction Direction, CpConnectionManager.Enum_A_ARG_TYPE_ConnectionStatus Status, UPnPInvokeException e, object Handle)
        {
            if (e != null)
            {
                return;
            }

            AVConnection av = null;

            lock (InstanceList)
            {
                foreach (AVConnection a in InstanceList)
                {
                    if (a.ConnectionID == ConnectionID)
                    {
                        av = a;
                        break;
                    }
                }
                if (av == null)
                {
                    av         = new AVConnection(MainDevice, AVTransportID, RcsID, ConnectionID, new AVConnection.OnReadyHandler(ReadySink), Handle);
                    av._Parent = this;
                    InstanceList.Add(av);
                }
                else
                {
                    return;                     // Don't need to trigger event
                }
            }

            // Wait for Ready before sending OnCreateConnection
        }
        /// <summary>
        /// This is called when PrepareForConnection was successful
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="c"></param>
        /// <param name="h"></param>
        protected void ConnectionSink(AVRenderer sender, AVConnection c, object h)
        {
            lock (ConnectionLock)
            {
                if (TableOfHandles.ContainsKey(h) == false)
                {
                    return;
                }
            }

            //			OpenSource.Utilities.InstanceTracker.StopTimer("PrepareForConnection");

            _AVR.OnCreateConnection2 -= new AVRenderer.ConnectionHandler(ConnectionSink);
            c.OnCurrentURIChanged    += new AVConnection.CurrentURIChangedHandler(UriEventSink);

            if (this.CurrentPlayListMode == PlayListMode.SINGLE_URI)
            {
                c.OnPlayStateChanged += new AVConnection.PlayStateChangedHandler(PlayStateSink);
            }
            c.CurrentPlayList = this;

            OpenSource.Utilities.InstanceTracker.StartTimer();

            //			c.SetAVTransportURI(PlayListUri, "", c, new CpAVTransport.Delegate_OnResult_SetAVTransportURI(SetURISink));
            c.SetAVTransportURI(PlayListUri, PlayListMetaData, c, new CpAVTransport.Delegate_OnResult_SetAVTransportURI(SetURISink));
        }
 private void PlayListSink(AVPlayList sender, AVConnection c, object Tag)
 {
     PlayListTable.Remove(sender.GetHashCode());
     if (OnReuseConnection != null)
     {
         OnReuseConnection(this, Tag);
     }
 }
        /// <summary>
        /// This get called when the URI events are received
        /// </summary>
        /// <param name="sender"></param>
        private void UriEventSink(AVConnection sender)
        {
            sender.OnCurrentURIChanged -= new AVConnection.CurrentURIChangedHandler(UriEventSink);
            this.SetURIEvent_Event.Set();

            if (SetURI_Event.WaitOne(0, false) == true)
            {
                //				OpenSource.Utilities.InstanceTracker.StopTimer("SetAVTransport+Event [evt]");
                if (OnReady != null)
                {
                    OnReady(this, sender, _Tag);
                }
                OnReady = null;
            }
        }
        /// <summary>
        /// This method is called when an Async call to PrepareForConnection returns. Only
        /// the AVPlayList class will ever call that method.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="RemoteProtocolInfo"></param>
        /// <param name="PeerConnectionManager"></param>
        /// <param name="PeerConnectionID"></param>
        /// <param name="Direction"></param>
        /// <param name="ConnectionID"></param>
        /// <param name="AVTransportID"></param>
        /// <param name="RcsID"></param>
        /// <param name="e"></param>
        /// <param name="Handle"></param>
        protected void PrepareForConnectionSink(CpConnectionManager sender, System.String RemoteProtocolInfo, System.String PeerConnectionManager, System.Int32 PeerConnectionID, CpConnectionManager.Enum_A_ARG_TYPE_Direction Direction, System.Int32 ConnectionID, System.Int32 AVTransportID, System.Int32 RcsID, UPnPInvokeException e, object Handle)
        {
            AVConnection c     = null;
            bool         IsNew = true;

            if (e != null)
            {
                // Since only the AVPlayList class will call PrepareForConnection, we need to fire
                // this other event, because it's too early to notify the user. Only AVPlayList needs
                // to know about this, so it can continue to setup the connection for the user
                OnCreateConnectionFailedEvent2.Fire(this, AVRenderer.CreateFailedReason.CREATE_ATTEMPT_DENIED, Handle);
                return;
            }

            lock (InstanceList)
            {
                foreach (AVConnection a in InstanceList)
                {
                    if (a.ConnectionID == ConnectionID)
                    {
                        // We Already Have this ID From somewhere
                        IsNew = false;
                        c     = a;
                        break;
                    }
                }
                if (IsNew == true)
                {
                    // Does not Exist
                    c         = new AVConnection(MainDevice, AVTransportID, RcsID, ConnectionID, new AVConnection.OnReadyHandler(_ReadySink), Handle);
                    c._Parent = this;
                    InstanceList.Add(c);
                }
            }

            if (IsNew == true)
            {
                // Wait for Ready event from the AVConnection, since we can't return it
                // until it is initialized.
            }
            else
            {
                // Recycled
                OnRecycledConnectionEvent2.Fire(this, c, Handle);
            }
        }
        /// <summary>
        /// This constructor is called with the UPnPDevice that contains the services of a MediaRenderer device.
        /// </summary>
        /// <param name="device">The UPnPDevice</param>
        public AVRenderer(UPnPDevice device)
        {
            OpenSource.Utilities.InstanceTracker.Add(this);
            this.ConnectionMonitor.OnExpired += new LifeTimeMonitor.LifeTimeHandler(ConnectionMonitorSink);

            MainDevice        = device;
            ConnectionManager = new CpConnectionManager(device.GetServices(CpConnectionManager.SERVICE_NAME)[0]);
            ConnectionManager.OnStateVariable_CurrentConnectionIDs += new CpConnectionManager.StateVariableModifiedHandler_CurrentConnectionIDs(ConnectionIDEventSink);
            ConnectionManager._subscribe(90);
            //TODO: Fails to compile after using generated code from DeviceBuilderV23. Seems like CpConnectionManager.PeriodicRenewFailedHandler is no longer defined?
            //ConnectionManager.OnPeriodicRenewFailed += new CpConnectionManager.PeriodicRenewFailedHandler(PeriodicRenewFailedSink);

            // Grab initial state of the ConnectionManager Service
            if (ConnectionManager.HasAction_GetProtocolInfo)
            {
                ConnectionManager.GetProtocolInfo(null, new CpConnectionManager.Delegate_OnResult_GetProtocolInfo(GetProtocolInfoSink));
            }
            if (ConnectionManager.HasAction_GetCurrentConnectionIDs)
            {
                ConnectionManager.GetCurrentConnectionIDs(null, new CpConnectionManager.Delegate_OnResult_GetCurrentConnectionIDs(IDSink));
            }
            if (ConnectionManager.HasAction_PrepareForConnection == false)
            {
                lock (InstanceList)
                {
                    AVConnection ac = new AVConnection(MainDevice, 0, 0, 0, new AVConnection.OnReadyHandler(ReadySink), null);
                    ac._Parent     = this;
                    DontEverDelete = true;
                    if (InstanceList.Count == 0)
                    {
                        InstanceList.Add(ac);
                    }
                }

                /*  Wait for Ready
                 * if(InstanceList.Count>0)
                 * {
                 *      if(OnCreateConnection!=null) OnCreateConnection(this,(AVConnection)InstanceList[0],Guid.NewGuid().GetHashCode());
                 * }
                 */
            }
        }
        protected void PlayListSink(AVPlayList sender, AVConnection c, object Tag)
        {
            PlayListTable.Remove(sender.GetHashCode());
            lock (this.CreateConnectionLock)
            {
                --this.PendingCreateConnection;
                if (this.PendingCreateConnection < 0)
                {
                    PendingCreateConnection = 0;
                }
                ConnectionMonitor.Remove(c.ConnectionID);
            }

            if (sender.IsRecycled)
            {
                OnRecycledConnectionEvent.Fire(this, c, Tag);
            }
            else
            {
                OnCreateConnectionEvent.Fire(this, c, Tag);
            }
        }
        /// <summary>
        /// This method gets called when the PlayState of the connection changes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="NewState"></param>
        protected void PlayStateSink(AVConnection sender, AVConnection.PlayState NewState)
        {
            if (NewState == AVConnection.PlayState.STOPPED)
            {
                if (FakePlayQueue.Count == 0)
                {
                    return;
                }

                if (sender.MediaResource.ContentUri != PlayListUri)
                {
                    // Somebody else changed the Uri from under us, so we have no choice
                    // but to give up
                    FakePlayQueue.Clear();
                    return;
                }

                IMediaResource r = (IMediaResource)FakePlayQueue.Dequeue();
                PlayListUri = r.ContentUri;
                //ToDo: Add MetaData
                sender.SetAVTransportURI(r.ContentUri, "", sender, new CpAVTransport.Delegate_OnResult_SetAVTransportURI(FakePlayListSink));
            }
        }
        /// <summary>
        /// This is called when PrepareForConnection was successful and
        /// returned a recycled connection id
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="c"></param>
        /// <param name="h"></param>
        protected void RecycledSink(AVRenderer sender, AVConnection c, object h)
        {
            lock (ConnectionLock)
            {
                if (TableOfHandles.ContainsKey(h) == false)
                {
                    return;
                }
            }

            _AVR.OnRecycledConnection2 -= new AVRenderer.ConnectionHandler(RecycledSink);

            IsRecycled             = true;
            c.OnCurrentURIChanged += new AVConnection.CurrentURIChangedHandler(UriEventSink);

            if (this.CurrentPlayListMode == PlayListMode.SINGLE_URI)
            {
                c.OnPlayStateChanged += new AVConnection.PlayStateChangedHandler(PlayStateSink);
            }
            c.CurrentPlayList = this;

            //			c.SetAVTransportURI(PlayListUri, "", c, new CpAVTransport.Delegate_OnResult_SetAVTransportURI(this.SetURISink));
            c.SetAVTransportURI(PlayListUri, PlayListMetaData, c, new CpAVTransport.Delegate_OnResult_SetAVTransportURI(this.SetURISink));
        }
 protected void RendererRemovedConnectionSink(AVRenderer sender, AVConnection r, object Handle)
 {
     UpdateUserInterface();
 }
 protected void RendererRecycledConnectionSink(AVRenderer sender, AVConnection r, object Handle)
 {
     if (renderer != sender) MessageBox.Show(this,"Incorrect renderer event");
     if (r != connection && (connection == null || (long)Handle == PendingConnection))
     {
         if (connection != null)
         {
             connection.OnMediaResourceChanged -= new AVConnection.MediaResourceChangedHandler(OnMediaResourceChangedHandlerSink);
             connection.OnMute -= new AVConnection.MuteStateChangedHandler(MuteStateChangedHandlerSink);
             connection.OnPlayStateChanged -= new AVConnection.PlayStateChangedHandler(PlayStateChangedHandlerSink);
             connection.OnPositionChanged -= new AVConnection.PositionChangedHandler(PositionChangedHandlerSink);
             connection.OnRemoved -= new AVConnection.RendererHandler(RemovedConnectionHandlerSink);
             connection.OnVolume -= new AVConnection.VolumeChangedHandler(VolumeChangedHandlerSink);
         }
         connection = r;
         connection.OnMediaResourceChanged += new AVConnection.MediaResourceChangedHandler(OnMediaResourceChangedHandlerSink);
         connection.OnMute += new AVConnection.MuteStateChangedHandler(MuteStateChangedHandlerSink);
         connection.OnPlayStateChanged += new AVConnection.PlayStateChangedHandler(PlayStateChangedHandlerSink);
         connection.OnPositionChanged += new AVConnection.PositionChangedHandler(PositionChangedHandlerSink);
         connection.OnRemoved += new AVConnection.RendererHandler(RemovedConnectionHandlerSink);
         connection.OnVolume += new AVConnection.VolumeChangedHandler(VolumeChangedHandlerSink);
     }
     UpdateUserInterface();
 }
        private void VolumeChangedHandlerSink(AVConnection sender, UInt16 Volume)
        {
            if (connection != sender) return;

            volumeTrackBar.Value = (int)connection.MasterVolume;
        }
        private void RendererControlForm_Closed(object sender, System.EventArgs e)
        {
            if (connection != null)
            {
                connection.OnMediaResourceChanged -= new AVConnection.MediaResourceChangedHandler(OnMediaResourceChangedHandlerSink);
                connection.OnMute -= new AVConnection.MuteStateChangedHandler(MuteStateChangedHandlerSink);
                connection.OnPlayStateChanged -= new AVConnection.PlayStateChangedHandler(PlayStateChangedHandlerSink);
                connection.OnPositionChanged -= new AVConnection.PositionChangedHandler(PositionChangedHandlerSink);
                connection.OnRemoved -= new AVConnection.RendererHandler(RemovedConnectionHandlerSink);
                connection.OnVolume -= new AVConnection.VolumeChangedHandler(VolumeChangedHandlerSink);
                connection = null;
            }

            parent.RendererControlFormClose(this,renderer);
        }
        private void CurrentTrackChangedHandlerSink(AVConnection sender, uint track)
        {
            if (sender != connection) return;
            if (mediaProgressBar.Tag != null) return;
            if (InvokeRequired) { Invoke(new CurrentTrackChangedHandler(CurrentTrackChangedHandlerSink), sender, track); return; }

            UpdateUserInterface();
        }
 private void MediaResourceChangedHandlerSink(AVConnection connection, IMediaResource res)
 {
     if (InvokeRequired) { Invoke(new AVConnection.MediaResourceChangedHandler(MediaResourceChangedHandlerSink), connection, res); return; }
     if (listViewSelectedObject == connection) SetListInfo(connection);
 }
        private void MuteStateChangedHandlerSink(AVConnection sender, bool NewMuteStatus)
        {
            if (sender != connection) return;

            muteMenuItem.Checked = connection.IsMute;
            if (connection.IsMute == true)
            {
                muteButton.Image = mutedPictureBox.Image;
            }
            else
            {
                muteButton.Image = mutePictureBox.Image;
            }
        }
 private void RemovedConnectionHandlerSink(AVConnection connection)
 {
     if (InvokeRequired) { Invoke(new AVConnection.RendererHandler(RemovedConnectionHandlerSink), connection); return; }
     TreeNode node = NodeTagSearch(rendererRootNode, connection);
     if (node != null) node.Remove();
     connection.OnVolume -= new AVConnection.VolumeChangedHandler(VolumeChangedHandlerSink);
     connection.OnPlayStateChanged -= new AVConnection.PlayStateChangedHandler(PlayStateChangedHandlerSink);
     connection.OnMute -= new AVConnection.MuteStateChangedHandler(MuteStateChangedHandlerSink);
     connection.OnPositionChanged -= new AVConnection.PositionChangedHandler(PositionChangedHandlerSink);
     connection.OnRemoved -= new AVConnection.RendererHandler(RemovedConnectionHandlerSink);
     connection.OnTrackChanged -= new AVConnection.CurrentTrackChangedHandler(TrackChangedSink);
     connection.OnCurrentMetaDataChanged -= new AVConnection.CurrentMetaDataChangedHandler(MetaDataSink);
 }
 private void PlayStateChangedHandlerSink(AVConnection connection, AVConnection.PlayState NewState)
 {
     if (InvokeRequired) { Invoke(new AVConnection.PlayStateChangedHandler(PlayStateChangedHandlerSink), connection, NewState); return; }
     TreeNode node = NodeTagSearch(rendererRootNode, connection);
     if (node != null)  { node.Text = connection.ConnectionID.ToString() + " - " + connection.CurrentState.ToString(); }
     if (listViewSelectedObject == connection) SetListInfo(connection);
 }
 private void _ReadySink(AVConnection sender, object Tag)
 {
     OnCreateConnectionEvent2.Fire(this, sender, Tag);
 }
        private void PositionChangedHandlerSink(AVConnection sender, TimeSpan position)
        {
            if (sender != connection) return;
            if (mediaProgressBar.Tag != null) return;
            if (InvokeRequired) { Invoke(new PositionChangedHandler(PositionChangedHandlerSink), sender, position); return; }

            UpdateUserInterface();
        }
        public AVPlayList(AVConnection AVC, IMediaResource[] r, ReadyHandler rh, FailedHandler fh, object Tag)
        {
            OpenSource.Utilities.InstanceTracker.Add(this);
            AVRenderer AVR = AVC.Parent;

            _AVR = AVR;

            this.CurrentURIChangedHandler = new AVConnection.CurrentURIChangedHandler(UriEventSink);
            _Tag = Tag;

            /*
             * ArrayList branches = new ArrayList();
             * ToXmlData_Custom txdc = new ToXmlData_Custom();
             * foreach(IMediaResource R in r)
             * {
             *  if(branches.Contains(R.Owner)==false)
             *  {
             *      branches.Add(R.Owner);
             *  }
             *  txdc.Mappings[R] = false;
             * }
             *
             * MediaBuilder.container container = new MediaBuilder.container("Autogenerated Playlist");
             * container.ID = Guid.NewGuid().ToString();
             * container.IdIsValid = true;
             * ToXmlFormatter txf = new ToXmlFormatter();
             * txf.WriteResource = new ToXmlFormatter.ToXml_FormatResource(WriteResource);
             * txdc.DesiredProperties = new ArrayList();
             * txdc.IsRecursive = true;
             * txdc.VirtualOwner =  MediaBuilder.CreateContainer(container);
             *
             * // Obtain the DIDL-Lite MetaData
             * this.PlayListMetaData = MediaBuilder.BuildDidl(txf, txdc, branches);
             * if(PlayListMetaData.Length>32768) PlayListMetaData = "";
             */

            int  TempHandle = this.GetHashCode();
            bool Done       = false;

            OnReady  += rh;
            OnFailed += fh;

            AVR.OnCreateConnection2       += new AVRenderer.ConnectionHandler(ConnectionSink);
            AVR.OnRecycledConnection2     += new AVRenderer.ConnectionHandler(RecycledSink);
            AVR.OnCreateConnectionFailed2 += new AVRenderer.FailedConnectionHandler(FailedSink);

            if (r.Length == 1)
            {
                Done = true;
                _CurrentPlayListMode = PlayListMode.NOT_A_PLAYLIST;
                PlayListUri          = ConvertLocalFileToHTTPResource(r[0]);
                lock (ConnectionLock)
                {
                    TableOfHandles[TempHandle] = TempHandle;
                    ConnectionSink(_AVR, AVC, TempHandle);
                }
            }

            if ((Done == false && AVR.SupportsProtocolInfo(new ProtocolInfoString("http-get:*:audio/mpegurl:*")))
                ||
                (Done == false && AVR.SupportsProtocolInfo(new ProtocolInfoString("http-get:*:audio/x-mpegurl:*"))))
            {
                // Build M3U
                Done = true;
                _CurrentPlayListMode = PlayListMode.M3U;

                CheckMiniWebServer();

                StringBuilder M3U = new StringBuilder();
                if (AVPlayList.EnableExtendedM3U)
                {
                    M3U.Append("#EXTM3U\r\n");
                }
                foreach (IMediaResource R in r)
                {
                    if (AVPlayList.EnableExtendedM3U)
                    {
                        PrintExtInfLine(M3U, R);
                    }
                    M3U.Append(ConvertLocalFileToHTTPResource(R) + "\r\n");
                }

                M3UString   = M3U.ToString();
                PlayListUri = "http://" + AVR.Interface.ToString() + ":" + MWS.LocalIPEndPoint.Port.ToString() + "/item.m3u";

                lock (ConnectionLock)
                {
                    TableOfHandles[TempHandle] = TempHandle;
                    ConnectionSink(_AVR, AVC, TempHandle);
                }
            }

            // Use SINGLE_URI
            if (Done == false)
            {
                _CurrentPlayListMode = PlayListMode.SINGLE_URI;
                foreach (IMediaResource rsc in r)
                {
                    FakePlayQueue.Enqueue(rsc);
                }
                PlayListUri = r[0].ContentUri;
                FakePlayQueue.Dequeue();
                lock (ConnectionLock)
                {
                    TableOfHandles[TempHandle] = TempHandle;
                    ConnectionSink(_AVR, AVC, TempHandle);
                }
            }
        }
 private void CurrentTrackChangedHandlerSink(AVConnection sender, uint track)
 {
     if (sender != connection) return;
     if (mediaProgressBar.Tag != null) return;
     UpdateUserInterface();
 }
 private void VolumeChangedHandlerSink(AVConnection connection, UInt16 Volume)
 {
     if (InvokeRequired) { Invoke(new AVConnection.VolumeChangedHandler(VolumeChangedHandlerSink), connection, Volume); return; }
     if (listViewSelectedObject == connection) SetListInfo(connection);
 }
        private void instanceButton_Click(object sender, System.EventArgs e)
        {
            int i = renderer.Connections.IndexOf(connection)+1;
            if (i >= renderer.Connections.Count) i = 0;
            AVConnection nextconnection = (AVConnection)renderer.Connections[i];

            if (nextconnection == null || nextconnection == connection) return;

            // Unplug the connection
            connection.OnMediaResourceChanged -= new AVConnection.MediaResourceChangedHandler(OnMediaResourceChangedHandlerSink);
            connection.OnMute -= new AVConnection.MuteStateChangedHandler(MuteStateChangedHandlerSink);
            connection.OnPlayStateChanged -= new AVConnection.PlayStateChangedHandler(PlayStateChangedHandlerSink);
            connection.OnPositionChanged -= new AVConnection.PositionChangedHandler(PositionChangedHandlerSink);
            connection.OnRemoved -= new AVConnection.RendererHandler(RemovedConnectionHandlerSink);
            connection.OnVolume -= new AVConnection.VolumeChangedHandler(VolumeChangedHandlerSink);

            // Setup the new one
            connection = nextconnection;
            connection.OnMediaResourceChanged += new AVConnection.MediaResourceChangedHandler(OnMediaResourceChangedHandlerSink);
            connection.OnMute += new AVConnection.MuteStateChangedHandler(MuteStateChangedHandlerSink);
            connection.OnPlayStateChanged += new AVConnection.PlayStateChangedHandler(PlayStateChangedHandlerSink);
            connection.OnPositionChanged += new AVConnection.PositionChangedHandler(PositionChangedHandlerSink);
            connection.OnRemoved += new AVConnection.RendererHandler(RemovedConnectionHandlerSink);
            connection.OnVolume += new AVConnection.VolumeChangedHandler(VolumeChangedHandlerSink);

            UpdateUserInterface();
        }
 protected void RemovedConnectionSinkEx(AVRenderer sender, AVConnection r, object Handle)
 {
     TreeNode node = NodeTagSearch(rendererRootNode,r);
     if (node != null)
     {
         node.Remove();
     }
 }
 private void OnMediaResourceChangedHandlerSink(AVConnection sender, IMediaResource target)
 {
     UpdateUserInterface();
 }
 private void VolumeChangedHandlerSink(AVConnection sender, UInt16 volume)
 {
     masterTrackBar.Value = (int)connection.MasterVolume;
 }
 private void MuteStateChangedHandlerSink(AVConnection connection, bool NewMuteStatus)
 {
     if (InvokeRequired) { Invoke(new AVConnection.MuteStateChangedHandler(MuteStateChangedHandlerSink), connection, NewMuteStatus); return; }
     if (listViewSelectedObject == connection) SetListInfo(connection);
 }
        private void VolumeChangedHandlerSink(AVConnection sender, UInt16 Volume)
        {
            if (connection != sender) return;
            if (InvokeRequired) { Invoke(new VolumeChangedHandlerSinkHandler(VolumeChangedHandlerSink), sender, Volume); return; }

            volumeTrackBar.Value = (int)connection.MasterVolume;
        }
 private void PositionChangedHandlerSink(AVConnection connection, TimeSpan time)
 {
     if (InvokeRequired) { Invoke(new AVConnection.PositionChangedHandler(PositionChangedHandlerSink), connection, time); return; }
     if (listViewSelectedObject == connection)
     {
         lock (listInfo)
         {
             listInfo.Items[1].SubItems[1].Text = connection.CurrentPosition.ToString();
             listInfo.Items[4].SubItems[1].Text = connection.Duration.ToString();
         }
     }
 }
        private void PlayStateChangedHandlerSink(AVConnection sender, AVConnection.PlayState NewState)
        {
            if (sender != connection) return;

            playButton.Image = playPictureBox2.Image;
            recordButton.Image = recordPictureBox2.Image;
            stopButton.Image = stopPictureBox2.Image;
            pauseButton.Image = pausePictureBox2.Image;

            switch (NewState)
            {
                case AVConnection.PlayState.PLAYING:
                    playButton.Image = playPictureBox1.Image;
                    playMenuItem.Checked = true;
                    recordMenuItem.Checked = false;
                    stopMenuItem.Checked = false;
                    pauseMenuItem.Checked = false;
                    break;
                case AVConnection.PlayState.RECORDING:
                    recordButton.Image = recordPictureBox1.Image;
                    playMenuItem.Checked = false;
                    recordMenuItem.Checked = true;
                    stopMenuItem.Checked = false;
                    pauseMenuItem.Checked = false;
                    break;
                case AVConnection.PlayState.SEEKING:
                    stopButton.Image = stopPictureBox1.Image;
                    playMenuItem.Checked = false;
                    recordMenuItem.Checked = false;
                    stopMenuItem.Checked = true;
                    pauseMenuItem.Checked = false;
                    break;
                case AVConnection.PlayState.STOPPED:
                    stopButton.Image = stopPictureBox1.Image;
                    playMenuItem.Checked = false;
                    recordMenuItem.Checked = false;
                    stopMenuItem.Checked = true;
                    pauseMenuItem.Checked = false;
                    break;
                case AVConnection.PlayState.PAUSED:
                    pauseButton.Image = pausePictureBox1.Image;
                    playMenuItem.Checked = false;
                    recordMenuItem.Checked = false;
                    stopMenuItem.Checked = false;
                    pauseMenuItem.Checked = true;
                    break;
            }
        }
 private void TrackChangedSink(AVConnection connection, UInt32 NewTrack)
 {
     if (InvokeRequired) { Invoke(new AVConnection.CurrentTrackChangedHandler(TrackChangedSink), connection, NewTrack); return; }
     if (listViewSelectedObject == connection)
     {
         lock (listInfo)
         {
             listInfo.Items[3].SubItems[1].Text = connection.CurrentTrack.ToString();
             listInfo.Items[13].SubItems[1].Text = connection.NumberOfTracks.ToString();
         }
     }
 }
        public RendererControlForm(MainForm parent, AVRenderer renderer, AVConnection connection)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.parent = parent;
            this.renderer = renderer;
            this.connection = connection;

            renderer.OnCreateConnection += new AVRenderer.ConnectionHandler(RendererCreateConnectionSink);
            renderer.OnRecycledConnection += new AVRenderer.ConnectionHandler(RendererRecycledConnectionSink);
            renderer.OnRemovedConnection +=  new AVRenderer.ConnectionHandler(RendererRemovedConnectionSink);

            if (connection == null && renderer.Connections.Count > 0)
            {
                connection = (AVConnection)renderer.Connections[0];
                this.connection = connection;
            }

            if (connection != null)
            {
                connection.OnMediaResourceChanged += new AVConnection.MediaResourceChangedHandler(OnMediaResourceChangedHandlerSink);
                connection.OnMute += new AVConnection.MuteStateChangedHandler(MuteStateChangedHandlerSink);
                connection.OnPlayStateChanged += new AVConnection.PlayStateChangedHandler(PlayStateChangedHandlerSink);
                connection.OnPositionChanged += new AVConnection.PositionChangedHandler(PositionChangedHandlerSink);
                connection.OnRemoved += new AVConnection.RendererHandler(RemovedConnectionHandlerSink);
                connection.OnTrackChanged += new AVConnection.CurrentTrackChangedHandler(CurrentTrackChangedHandlerSink);
                connection.OnVolume += new AVConnection.VolumeChangedHandler(VolumeChangedHandlerSink);
                volumeTrackBar.Value = (int)connection.MasterVolume;
                PositionChangedHandlerSink(connection, connection.CurrentPosition);

                muteMenuItem.Checked = connection.IsMute;
                if (connection.IsMute == true)
                {
                    muteButton.Image = mutedPictureBox.Image;
                }
                else
                {
                    muteButton.Image = mutePictureBox.Image;
                }
            }

            this.Text = "Renderer - " + renderer.FriendlyName;
            rendererNameLabel.Text = renderer.FriendlyName;

            if (connection != null) PlayStateChangedHandlerSink(connection,connection.CurrentState);
            UpdateUserInterface();
        }
 protected void MetaDataSink(AVConnection sender)
 {
     if (InvokeRequired) { Invoke(new AVConnection.CurrentMetaDataChangedHandler(MetaDataSink), sender); return; }
     SetListInfo(listViewSelectedObject);
 }
 protected void RendererRecycledConnectionSink(AVRenderer sender, AVConnection r, object Handle)
 {
     Object[] args = new Object[3];
     args[0] = sender;
     args[1] = r;
     args[2] = Handle;
     this.Invoke(new AVRenderer.ConnectionHandler(RendererRecycledConnectionSinkEx),args);
 }
 private void PositionChangedHandlerSink(AVConnection sender, TimeSpan position)
 {
     if (sender != connection) return;
     if (mediaProgressBar.Tag != null) return;
     UpdateUserInterface();
 }
 private void MuteStateChangedHandlerSink(AVConnection sender, bool NewMuteStatus)
 {
     masterMuteCheckBox.Checked = NewMuteStatus;
 }
        private void RemovedConnectionHandlerSink(AVConnection sender)
        {
            if (connection == sender)
            {
                // Unplug the connection
                connection.OnMediaResourceChanged -= new AVConnection.MediaResourceChangedHandler(OnMediaResourceChangedHandlerSink);
                connection.OnMute -= new AVConnection.MuteStateChangedHandler(MuteStateChangedHandlerSink);
                connection.OnPlayStateChanged -= new AVConnection.PlayStateChangedHandler(PlayStateChangedHandlerSink);
                connection.OnPositionChanged -= new AVConnection.PositionChangedHandler(PositionChangedHandlerSink);
                connection.OnRemoved -= new AVConnection.RendererHandler(RemovedConnectionHandlerSink);
                connection.OnVolume -= new AVConnection.VolumeChangedHandler(VolumeChangedHandlerSink);
                connection = null;

                if (renderer.Connections.Count > 0)
                {
                    connection = (AVConnection)renderer.Connections[0];
                    connection.OnMediaResourceChanged += new AVConnection.MediaResourceChangedHandler(OnMediaResourceChangedHandlerSink);
                    connection.OnMute += new AVConnection.MuteStateChangedHandler(MuteStateChangedHandlerSink);
                    connection.OnPlayStateChanged += new AVConnection.PlayStateChangedHandler(PlayStateChangedHandlerSink);
                    connection.OnPositionChanged += new AVConnection.PositionChangedHandler(PositionChangedHandlerSink);
                    connection.OnRemoved += new AVConnection.RendererHandler(RemovedConnectionHandlerSink);
                    connection.OnVolume += new AVConnection.VolumeChangedHandler(VolumeChangedHandlerSink);
                }
            }
            UpdateUserInterface();
        }
Beispiel #41
0
		protected void PlayListSink(AVPlayList sender, AVConnection c, object Tag)
		{
			PlayListTable.Remove(sender.GetHashCode());
			lock(this.CreateConnectionLock)
			{
				--this.PendingCreateConnection;
				if(this.PendingCreateConnection<0) PendingCreateConnection = 0;
				ConnectionMonitor.Remove(c.ConnectionID);
			}

			if(sender.IsRecycled)
			{
				OnRecycledConnectionEvent.Fire(this,c,Tag);
			}
			else
			{
				OnCreateConnectionEvent.Fire(this,c,Tag);
			}
		}