简体   繁体   中英

How to import .CDA tracks from a CD in windows 10 universal app?

I need to import tracks from a CD but so far I am unable in doing so. I can successfully import .mp3 or many other audio formats from a CD. For importing purpose first I scan files and folder of a CD. Then I show the list of files to user and copy files that user selects from list.

Here is my code for scanning a Directory or a CD:

    List<StorageFile> allTrackFiles = null;
    private async Task GetFiles(StorageFolder folder)
    {
        if(!scanningRemovableTask)
        {
            return;
        }
        try
        {

        if(allTrackFiles == null)
        {
            allTrackFiles = new List<StorageFile>();
        }
        var items = await folder.GetItemsAsync();

        foreach (var item in items)
        {
                if (item.GetType() == typeof(StorageFile))
                {
                    StorageFile storageFile = item as StorageFile;
                    allTrackFiles.Add(storageFile);

                    var basicProperties  = await storageFile.GetBasicPropertiesAsync();
                    var musicProperties = await storageFile.OpenReadAsync();
                }
                else
                    await GetFiles(item as StorageFolder);
        }

        }
        catch(Exception e)
        {

        }
    }    

I pass the CD path to this function and it creates a list of files for me. This code works fine when CD has only .mp3 or any famous Audio format. But it creates trouble when CD has .CDA extension tracks. As we know that .CDA files are itself doesn't play, they are just shortcuts to the original media files.

Now, this is where I am stuck right now. How to read .CDA files or import .CDA files media to our local Directory in universal windows app.

Short answer: This is not possible with CDA files.

Long answer: A CDA file is just a stub file generated by Windows for each audio track on the CD. These files do not contain the actual audio data. All they contain is where on the disc each track starts and stops. If the file is "copied" from the CD to a computer, it cannot be used on its own because it is only a shortcut to part of the disc. An audio CD is not formatted as a file system disk. It cannot be accessed as files. That is why windows creates the CDA files. It displays the CD as a drive with files for the tracks just for easy viewing.

You will have to use a library that can load the actual audio tracks from the disk, not as files but as audio tracks. The proper way to use the CDA would be to use it as a reference to the actual audio track, rip that to a file, then load the ripped file.

You can use the native Windows Media Interface for ripping audio tracks. I also found a Code Project Tutorial that seems to be using a custom ripper. They should get you going in the right direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM