将播放列表保存到所需位置

时间:2013-08-25 11:47:21

标签: javascript windows-8 winjs

问题很简单:

我有一个播放列表

var playlist = new Windows.Media.Playlists.Playlist();

我想将此播放列表保存到我选择的文件夹中(例如桌面或D:\ New Folder \ Sub Folder)。问题是playlist.SaveAsAsync方法需要一个实现Windows.Storage.IStorageFolder的类,我不知道如何生成这样一个具有所需路径作为其根文件夹的类。

编辑目前使用文件夹选择器似乎可以完成这项工作,但是有什么办法可以通过文件选择器获取存储文件夹

1 个答案:

答案 0 :(得分:1)

我在C#中有解决方案,你可以在JS中轻松转换它。您需要使用FolderPicker选择您选择的位置来保存播放列表。您可以以3种格式保存播放列表。

  • Windows Media(* .wpl)

  • Zune(* .zpl)

  • M3U(* .m3u)

见下面给出的代码。

var playlist = new Playlist();

//audio1 to audio4 are the object of StorageFile class
playlist.Files.Add(audio1);
playlist.Files.Add(audio2);
playlist.Files.Add(audio3);
playlist.Files.Add(audio4);

/* Initialize folder picker. Music lib is suggested start location and I've added
storage file type filters. */

FolderPicker folderPicker = new FolderPicker();
folderPicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
folderPicker.FileTypeFilter.Add(".m3u");
folderPicker.FileTypeFilter.Add(".wpl");
folderPicker.FileTypeFilter.Add(".zpl");
StorageFolder folder = await folderPicker.PickSingleFolderAsync();

/* Playlist.SaveAsAsync takes four argument. First is destination folder, second is
 playlist name, 3rd is file collision option and 4th is playlist format */

var file = await playlist.SaveAsAsync(folder, "myplaylist", NameCollisionOption.GenerateUniqueName, PlaylistFormat.WindowsMedia);

Playlist.SaveAsAsync method - MSDN

FolderPicker class on MSDN