private async void ButtonPlayTrack_Click(object sender, RoutedEventArgs e) { string id = ListDevices.SelectedItem as string; if (!string.IsNullOrEmpty(id) && (id != "None")) { CDReaderDevice device = null; if (ListDeviceInformation != null) { foreach (var d in ListDeviceInformation) { if (d.Id == id) { device = d; } } } if (device != null) { try { { LogMessage("Device Name: " + device.Name); if ((ComboTrackNumber.Items != null) && (ComboTrackNumber.Items.Count > 0)) { CDTrackMetadata t = ComboTrackNumber.SelectedItem as CDTrackMetadata; if (t != null) { LogMessage("Playing Track " + t.Number.ToString()); await StartPlay(device.Id, t.FirstSector, t.LastSector); } } } } catch (UnauthorizedAccessException ex) { LogMessage("Exception while playing the media: " + ex.Message); } catch (Exception ex) { LogMessage("Exception while playing the media: " + ex.Message); } } } }
private async void ButtonEjectMedia_Click(object sender, RoutedEventArgs e) { string id = ListDevices.SelectedItem as string; if (!string.IsNullOrEmpty(id) && (id != "None")) { CDReaderDevice device = null; if (ListDeviceInformation != null) { foreach (var d in ListDeviceInformation) { if (d.Id == id) { device = d; } } } if (device != null) { try { { LogMessage("Device Name: " + device.Name); bool result = await cdReaderManager.EjectMedia(device.Id); if (result == true) { LogMessage("Media Ejection successful"); if (currentCD.Tracks != null) { currentCD.Tracks.Clear(); } FillComboTrack(); } } } catch (UnauthorizedAccessException ex) { LogMessage("Exception while ejecting the media: " + ex.Message); } catch (Exception ex) { LogMessage("Exception while ejecting the media: " + ex.Message); } } } }
private async void CDReaderDevice_Added(CDReaderManager sender, CDReaderDevice args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { if (ListDeviceInformation != null) { ListDeviceInformation.Add(args); } ListDevices.Items.Add(args.Id); CheckListDevices(); if (bAutoStart == true) { bAutoStart = false; ButtonReadCDMetadata_Click(null, null); } }); }
private async void ButtonReadCDMetadata_Click(object sender, RoutedEventArgs e) { string id = ListDevices.SelectedItem as string; if (!string.IsNullOrEmpty(id) && (id != "None")) { CDReaderDevice device = null; if (ListDeviceInformation != null) { foreach (var d in ListDeviceInformation) { if (d.Id == id) { device = d; } } } if (device != null) { try { LogMessage("Device Name: " + device.Name); currentCD = await cdReaderManager.ReadMediaMetadata(device.Id); if ((currentCD != null) && (currentCD.Tracks.Count > 1)) { FillComboTrack(); LogMessage("Get CD Table Map successfull: " + currentCD.Tracks.Count.ToString() + " tracks"); FillComboTrack(); } } catch (UnauthorizedAccessException ex) { LogMessage("Exception while reading Table: " + ex.Message); } catch (Exception ex) { LogMessage("Exception while reading Table: " + ex.Message); } } } }
private async void CDReaderDevice_Removed(CDReaderManager sender, CDReaderDevice args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { if ((ListDeviceInformation != null) && (ListDeviceInformation.Count > 0)) { foreach (var d in ListDeviceInformation) { if (d.Id == args.Id) { ListDeviceInformation.Remove(d); break; } } } ListDevices.Items.Remove(args.Id); CheckListDevices(); }); }
private async void ButtonExtractTrack_Click(object sender, RoutedEventArgs e) { string id = ListDevices.SelectedItem as string; if (!string.IsNullOrEmpty(id) && (id != "None")) { CDReaderDevice device = null; if (ListDeviceInformation != null) { foreach (var d in ListDeviceInformation) { if (d.Id == id) { device = d; } } } if (device != null) { try { { LogMessage("Device Name: " + device.Name); if ((ComboTrackNumber.Items != null) && (ComboTrackNumber.Items.Count > 0)) { CDTrackMetadata t = ComboTrackNumber.SelectedItem as CDTrackMetadata; if (t != null) { LogMessage("Extracting Track " + t.Number.ToString()); var filePicker = new Windows.Storage.Pickers.FileSavePicker(); filePicker.DefaultFileExtension = ".wav"; filePicker.SuggestedFileName = "track" + t.Number.ToString() + ".wav"; filePicker.FileTypeChoices.Add("WAV files", new List <string>() { ".wav" }); filePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary; filePicker.SettingsIdentifier = "WavPicker"; filePicker.CommitButtonText = "Save Track into a WAV File"; var wavFile = await filePicker.PickSaveFileAsync(); if (wavFile != null) { string fileToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(wavFile); if (await RecordTrack(wavFile.Path, device.Id, t.FirstSector, t.LastSector)) { LogMessage("Record track in WAV file: " + wavFile.Path.ToString()); } else { LogMessage("Error while saving record buffer in file: " + wavFile.Path.ToString()); } } } } } } catch (UnauthorizedAccessException ex) { LogMessage("Exception while ejecting the media: " + ex.Message); } catch (Exception ex) { LogMessage("Exception while ejecting the media: " + ex.Message); } } } }