无法在 windows phone 8 中使用 MediaLibraryExtensions.SaveSong 下载音频
Unable to download audio with MediaLibraryExtensions.SaveSong in windows phone 8
我正在尝试下载音频并保存到隔离存储并保存到模拟器。
我尝试了以下代码。
WebClient m_webClient = new WebClient();
m_webClient.OpenReadAsync(fileUri);
m_webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_ImageOpenReadCompleted);
m_webClient.AllowReadStreamBuffering = true;
private static void webClient_ImageOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
var isolatedfile = IsolatedStorageFile.GetUserStoreForApplication();
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(_fileName, System.IO.FileMode.Create, isolatedfile))
{
byte[] buffer = new byte[e.Result.Length];
while (e.Result.Read(buffer, 0, buffer.Length) > 0)
{
stream.Write(buffer, 0, buffer.Length);
}
}
SaveFileMP3(_fileName);
}
private static void SaveFileMP3(string _fileName)
{
MediaLibrary lib = new MediaLibrary();
Uri songUri = new Uri(_fileName, UriKind.RelativeOrAbsolute);
MediaLibraryExtensions.SaveSong(lib, songUri, null, SaveSongOperation.CopyToLibrary);
}
我面临的问题是,音频被保存到模拟器但没有扩展。假设文件名"test.MP3",保存为"test",无论原始时长如何,时长始终为0:0:00。
我也在清单文件中添加了音频功能。
下面是保存歌曲时的截图,里面有很多异常。
代码如有错误请指正。提前致谢。
通过添加 lib.savesong 行而不是使用 mediaLibraryExtensions 可以完美地工作。
private static void SaveFileMP3(string _fileName)
{
MediaLibrary lib = new MediaLibrary();
Uri songUri = new Uri(_fileName, UriKind.RelativeOrAbsolute);
lib.SaveSong(songUri, null, SaveSongOperation.CopyToLibrary);
//MediaLibraryExtensions.SaveSong(lib, songUri, null, SaveSongOperation.CopyToLibrary);
}
我正在尝试下载音频并保存到隔离存储并保存到模拟器。
我尝试了以下代码。
WebClient m_webClient = new WebClient();
m_webClient.OpenReadAsync(fileUri);
m_webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_ImageOpenReadCompleted);
m_webClient.AllowReadStreamBuffering = true;
private static void webClient_ImageOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
var isolatedfile = IsolatedStorageFile.GetUserStoreForApplication();
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(_fileName, System.IO.FileMode.Create, isolatedfile))
{
byte[] buffer = new byte[e.Result.Length];
while (e.Result.Read(buffer, 0, buffer.Length) > 0)
{
stream.Write(buffer, 0, buffer.Length);
}
}
SaveFileMP3(_fileName);
}
private static void SaveFileMP3(string _fileName)
{
MediaLibrary lib = new MediaLibrary();
Uri songUri = new Uri(_fileName, UriKind.RelativeOrAbsolute);
MediaLibraryExtensions.SaveSong(lib, songUri, null, SaveSongOperation.CopyToLibrary);
}
我面临的问题是,音频被保存到模拟器但没有扩展。假设文件名"test.MP3",保存为"test",无论原始时长如何,时长始终为0:0:00。
我也在清单文件中添加了音频功能。
下面是保存歌曲时的截图,里面有很多异常。
代码如有错误请指正。提前致谢。
通过添加 lib.savesong 行而不是使用 mediaLibraryExtensions 可以完美地工作。
private static void SaveFileMP3(string _fileName)
{
MediaLibrary lib = new MediaLibrary();
Uri songUri = new Uri(_fileName, UriKind.RelativeOrAbsolute);
lib.SaveSong(songUri, null, SaveSongOperation.CopyToLibrary);
//MediaLibraryExtensions.SaveSong(lib, songUri, null, SaveSongOperation.CopyToLibrary);
}