Playlist.SaveAsAsync doesn't work with the files from FileActivation


  • Hello,

    As in the topic, I can't save a playlist with the files from FileActivation. Here's my code:

    public async void NavigateToFilePage() { if (FileEvent != null) { ListViewPlaylist.Items.Clear(); streams.Clear(); filelist.Clear(); MusicInfo.Clear(); i = 1; size = 0; streams.Add(null); filelist.Add(null); MusicInfo.Add(null); open = false; int oldsize = size; size += FileEvent.Files.Count; i = oldsize + 1; for(int k=0;k<FileEvent.Files.Count;k++) { MusicInfo.Add(await ((StorageFile)FileEvent.Files[k]).Properties.GetMusicPropertiesAsync()); filelist.Add((StorageFile)FileEvent.Files[k]); // pageTitle.Text = file.Name.ToString(); streams.Add(await ((StorageFile)FileEvent.Files[k]).OpenAsync(Windows.Storage.FileAccessMode.Read)); Song qwer = new Song(); qwer.Id = i; qwer.Title = MusicInfo[i].Title; qwer.Album = MusicInfo[i].Album; qwer.Artist = MusicInfo[i].Artist; int dur = (int)Math.Round(MusicInfo[i].Duration.TotalSeconds); qwer.Duration = TimeSpan.FromSeconds(dur).ToString(); ListViewPlaylist.Items.Add(qwer); i++; } if (oldsize == 0) { currenttrack = 0; interval.Start(); ind = 0; next_track(false); } } }

    and here's the save function:

     private async void save()
                for(int j=1; j <= ListViewPlaylist.Items.Count; j++)
                FileSavePicker savePicker = new FileSavePicker();
                savePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
                // Dropdown of file types the user can save the file as
                //savePicker.FileTypeChoices.Add("m3u playlist", new List<string>() { ".m3u" });
                // Default file name if the user does not type one in or select a file to replace
                savePicker.SuggestedFileName = "Playlist1";
                savePicker.FileTypeChoices.Add("m3u", new List<string>() { ".m3u" });
                savePicker.FileTypeChoices.Add("wpl", new List<string>() { ".wpl" });
                savePicker.FileTypeChoices.Add("zpl", new List<string>() { ".zpl" });
                StorageFile file = await savePicker.PickSaveFileAsync();
                if (file != null)
                    // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync.
                   // CachedFileManager.DeferUpdates(file);
                    // write to file
                    //await FileIO.WriteLinesAsync(file, playlist);
                    IStorageFolder folder = await file.GetParentAsync();
                    //string qr = folder.Path;
                    //StorageFolder zxc = await StorageFolder.GetFolderFromPathAsync(file.Path);
                    String name = Path.GetFileNameWithoutExtension(file.Name);
                    var asd = Path.GetExtension(file.Name);
                    PlaylistFormat ext = new PlaylistFormat();
                    if (asd == ".m3u")
                        ext = PlaylistFormat.M3u;
                    if (asd == ".wpl")
                        ext = PlaylistFormat.WindowsMedia;
                    if (asd == ".zpl")
                        ext = PlaylistFormat.Zune;                
                    await list.SaveAsAsync(folder,name,NameCollisionOption.ReplaceExisting, ext);//that function doesn't work
    If I add the files to the FileList<StorageFile> by file picker, everything is ok. What is the diffrence between StorageFile from Picker and StorageFile from FileActivation? The files are loaded correctly, because I can do some other things like reading the paths and gathering the extensions. What is the problem?

    Wednesday, March 5, 2014 9:38 PM

All replies

  • What exactly is going wrong where? In what way does the save fail? Do you get an error? What results do you expect and how does that differ from what you get?

    Can you provide a minimal sample that demonstrates the problem? The code you list here is partial enough that it's not clear exactly what it's doing.


    Thursday, March 6, 2014 2:13 AM
  • Function SaveAsAsync throws an error. HRESULT: 0x80073D54. The sample:

    1. I open the appkication by "open with" option, and load the file into the list<StorageFile>filelist.

    2. Some other things happen, like adding RandomAccesStreams, and MusicProperties, but it doesn't have any influence on the playlist.

    3. In the function save(), I add the files to the Playlist list.

    4. I try to save the playlist, but SaveAsAsync throws an error.

    If I add the files to the list<StorageFile>filelist by file picker, the playlist is saved without any problems.

    I can add the OnFileActivated function:

    protected override async void OnFileActivated(FileActivatedEventArgs args)
                Frame rootFrame = Window.Current.Content as Frame;
                // Do not repeat app initialization when the Window already has content,
                // just ensure that the window is active
                if (rootFrame == null)
                    // Create a Frame to act as the navigation context and navigate to the first page
                    rootFrame = new Frame();
                    // Associate the frame with a SuspensionManager key
                    SuspensionManager.RegisterFrame(rootFrame, "AppFrame");
                    if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                        // Restore the saved session state only when appropriate
                            await SuspensionManager.RestoreAsync();
                        catch (SuspensionManagerException)
                            //Something went wrong restoring state.
                            //Assume there is no state and continue
                    // Place the frame in the current Window
                    Window.Current.Content = rootFrame;
                if (rootFrame.Content == null)
                    if (!rootFrame.Navigate(typeof(MainPage)))
                        throw new Exception("Failed to create initial page");
                var p = rootFrame.Content as MainPage;
                p.FileEvent = args;
                p.ProtocolEvent = null;
                // Ensure the current window is active

    And the FileEvent,

    private FileActivatedEventArgs _fileEventArgs/* = null*/;
            public FileActivatedEventArgs FileEvent
                get { return _fileEventArgs; }
                set { _fileEventArgs = value; }

    Thursday, March 6, 2014 3:50 PM