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 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); } } } }