locked
Music Library Control and Database RRS feed

  • Question

  • Since METRO applications cant access databases like SQLite, what is the correct approach to:

    1-) Store the reference to the items added by the user? XML is the most indicated way? Since i am developing a music player, there will be a huge amount of items. Wouldnt that make the XML parser takes too long to execute?

    2-) Since User add files throught FilePicker and the file isn't accessible by the application (on a path like "c:\temp\musics" wich isn't a library folder) the right thing to do is Copy this file to a music library folder for future use? Or files added by filepicker can be accessed later?

    3-) What is the correct way to store the file reference for future use? Windows path? A relative Path?

    Thanks

    Thursday, May 17, 2012 8:43 PM

Answers

  • I managed how to store the file references for each library item.

                    FileOpenPicker openPicker = new FileOpenPicker();
                    openPicker.ViewMode = PickerViewMode.List;
                    openPicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
                    openPicker.FileTypeFilter.Add(".mp3");
                    openPicker.FileTypeFilter.Add(".wma");
                    IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();
                    if (files.Count > 0)
                    {
                        // Application now has read/write access to the picked file(s)
    
                        foreach (StorageFile file in files)
                        {
                          var listToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
    
                          //now save the token for future use on your XML or txt file
                          this.addMusicToken(listToken);
                          this.loadFile(file);
                        }
                    }

    The code above opens the file picker and receive a list of StorageFile.

    Each file returned by the file picker call is then added to FutureAccessList and receives a token.

    This token can be used later (even after closing the application) to recover the StorageFile added to the list. The code bellow show the acquisition of the file using the token.

    String fileToken;
    var file = await Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.GetFileAsync(fileToken);
    • Proposed as answer by Evandro Gomes Friday, May 18, 2012 3:01 PM
    • Marked as answer by lcaldoncelli Friday, May 18, 2012 5:18 PM
    Friday, May 18, 2012 2:25 PM

All replies

  • You can cache access privileges to StorageFiles returned from the FileOpenPicker with Windows.Storage.AccessCache.

    See Accessing files with file pickers, Guidelines and checklist for file pickers, and the File access sample.

    If you are talking about music files themselves then using the Music Library is appropriate. If you are talking about sidecar files for your own app's use then they should be stored in your app data store.

    --Rob

    Thursday, May 17, 2012 11:33 PM
    Moderator
  • I managed how to store the file references for each library item.

                    FileOpenPicker openPicker = new FileOpenPicker();
                    openPicker.ViewMode = PickerViewMode.List;
                    openPicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
                    openPicker.FileTypeFilter.Add(".mp3");
                    openPicker.FileTypeFilter.Add(".wma");
                    IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();
                    if (files.Count > 0)
                    {
                        // Application now has read/write access to the picked file(s)
    
                        foreach (StorageFile file in files)
                        {
                          var listToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
    
                          //now save the token for future use on your XML or txt file
                          this.addMusicToken(listToken);
                          this.loadFile(file);
                        }
                    }

    The code above opens the file picker and receive a list of StorageFile.

    Each file returned by the file picker call is then added to FutureAccessList and receives a token.

    This token can be used later (even after closing the application) to recover the StorageFile added to the list. The code bellow show the acquisition of the file using the token.

    String fileToken;
    var file = await Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.GetFileAsync(fileToken);
    • Proposed as answer by Evandro Gomes Friday, May 18, 2012 3:01 PM
    • Marked as answer by lcaldoncelli Friday, May 18, 2012 5:18 PM
    Friday, May 18, 2012 2:25 PM