private void MainForm_Load(object sender, EventArgs e)
        {
            if (applicationLogic == null)
            {
                return;
            }

            Update();
            AddIP4Addresses();
            applicationLogic.Initialize();
            NetworkChange.NetworkAddressChanged     += new NetworkAddressChangedEventHandler(AddressChangedCallback);
            cmbIP4AddressUsed.SelectedIndexChanged  += CmbIP4AddressUsed_SelectedIndexChanged;
            cmbBufferInSeconds.SelectedIndexChanged += CmbBufferInSeconds_SelectedIndexChanged;

            Assembly        assembly = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);

            FillStreamFormats();
            FillFilterDevices();
            lblVersion.Text = $"{Properties.Strings.Version} {fvi.FileVersion}";
            applicationLogic.StartTask(() =>
            {
                CheckForNewVersion(fvi.FileVersion);
            });
            loopbackRecorder.Start(this, applicationLogic.OnRecordingDataAvailable, applicationLogic.ClearMp3Buffer);
        }
        /// <summary>
        /// A new device is discoverd. Add the device, or update if it already exists.
        /// </summary>
        /// <param name="discoveredDevice">the discovered device</param>
        public void OnDeviceAvailable(DiscoveredDevice discoveredDevice)
        {
            if (deviceList == null || discoveredDevice == null)
            {
                return;
            }

            if (discoveredDevice.Port == 0 || discoveredDevice.Port == 10001)
            {
                return;
            }

            if (!discoveredDevice.AddedByDeviceInfo && !discoveredDevice.IsGroup)
            {
                applicationLogic.StartTask(DeviceInformation.GetDeviceInformation(discoveredDevice, SetDeviceInformation, logger));
            }
            else
            {
                lock (deviceList)
                {
                    var existingDevice = GetDevice(discoveredDevice);
                    if (existingDevice == null)
                    {
                        var newDevice = DependencyFactory.Container.Resolve <Device>();
                        newDevice.Initialize(discoveredDevice, SetDeviceInformation, StopGroup, applicationLogic.StartTask);
                        deviceList.Add(newDevice);
                        onAddDeviceCallback?.Invoke(newDevice);

                        var wasPlaying = applicationLogic.WasPlaying(discoveredDevice);
                        if ((AutoStart && !newDevice.IsGroup()) || (StartLastUsedDevices && wasPlaying))
                        {
                            newDevice.ResumePlaying();
                        }
                    }
                    else
                    {
                        existingDevice.Initialize(discoveredDevice, SetDeviceInformation, StopGroup, applicationLogic.StartTask);
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Handle a close message from the device.
        /// </summary>
        /// <param name="closeMessage">the close message</param>
        private void OnReceiveCloseMessage(PayloadMessageBase closeMessage)
        {
            if (applicationLogic == null || device == null || IsDisposed)
            {
                return;
            }

            if (!(applicationLogic.GetAutoRestart()))
            {
                userMode = UserMode.Stopped;
            }

            var deviceState = device.GetDeviceState();

            if (deviceState == DeviceState.Playing ||
                deviceState == DeviceState.Buffering ||
                deviceState == DeviceState.Paused ||
                deviceState == DeviceState.LoadingMedia ||
                deviceState == DeviceState.LoadingMediaCheckFirewall)
            {
                Stop();
            }
            device.SetDeviceState(DeviceState.Closed, null);
            Connected = false;
            var cancellationTokeSource = new CancellationTokenSource();

            applicationLogic.StartTask(() => {
                for (int i = 0; i < 20; i++)
                {
                    Task.Delay(100).Wait();

                    if (cancellationTokeSource.IsCancellationRequested)
                    {
                        return;
                    }
                }

                GetReceiverStatus();
            }, cancellationTokeSource);
        }