/// <summary> /// Handle a device being mounted. /// </summary> /// <param name='sender'> /// The event sender. /// </param> /// <param name='e'> /// The event arguments. /// </param> private void MountManagerOnMounted(object sender, MountedDeviceEventArgs e) { Logger.Debug("Mounted " + e.Device.Device + " to " + e.Device.MountPath); Thread discoveryThread = new Thread(AudioDiscoveryThread) { IsBackground = true, Name = "Audio Discovery " + e.Device.Device }; lock (_discoveryThreads) _discoveryThreads.Add(e.Device, discoveryThread); lock (_mountedDeviceUuids) _mountedDeviceUuids.Add(e.Device.Uuid); Controller.AudioPlayer.NotifyDeviceOffline(e.Device.Uuid); discoveryThread.Start(e.Device); }
/// <summary> /// Handle a device being unmounted. /// </summary> /// <param name='sender'> /// The event sender. /// </param> /// <param name='e'> /// The event arguments. /// </param> private void MountManagerOnUnmounted(object sender, MountedDeviceEventArgs e) { Logger.Debug("Unmounted " + e.Device.Device + " from " + e.Device.MountPath); lock (_mountedDeviceUuids) if (_mountedDeviceUuids.Contains(e.Device.Uuid)) { _mountedDeviceUuids.Remove(e.Device.Uuid); } lock (_discoveryThreads) { if (_discoveryThreads.ContainsKey(e.Device)) { // Force the thread to terminate try { _discoveryThreads[e.Device].Abort(); } catch { } _discoveryThreads.Remove(e.Device); } } // Get all files for this audio source and set them offline AudioFile[] filesOnDevice = AudioFileFactory.ApplicationInstance.ReadAll().Where(audioFile => audioFile.DeviceUuid == e.Device.Uuid).ToArray(); if (filesOnDevice.Length < 1) { return; } AudioLibraryUpdateNotification notification = new AudioLibraryUpdateNotification(); foreach (AudioFile audioFile in filesOnDevice) { notification.OfflineFiles.Add(audioFile.AudioFileId); } Controller.NotificationNetworkServer.SendNotification(notification); }