Medialibrary Savesong方法破坏了文件

时间:2013-01-21 09:37:36

标签: vb.net windows-phone-8 windows-phone media-library

以下是我在MSDN论坛上找到的代码:

    Dim file As New Uri("Assets/someSong.mp3", UriKind.Relative)     
    Dim myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()
    Dim fileStream As IsolatedStorageFileStream = myIsolatedStorage.CreateFile("someSong.mp3")
    Dim resource = Application.GetResourceStream(file)
Dim chunkSize As Integer = 4096
    Dim bytes As Byte() = New Byte(chunkSize - 1) {}
    Dim byteCount As Integer
    While resource.Stream.Read(bytes, 0, chunkSize) > 0
        byteCount = resource.Stream.Read(bytes, 0, chunkSize)
        fileStream.Write(bytes, 0, byteCount)
    End While
    fileStream.Close()
    Dim metaData As New Microsoft.Xna.Framework.Media.PhoneExtensions.SongMetadata()
    metaData.AlbumName = "Some Album name"
    metaData.ArtistName = "Some Artist Name"
    metaData.GenreName = "test"
    metaData.Name = "someSongName"
    metaData.Duration = TimeSpan.FromSeconds(185)
    Dim ml = New MediaLibrary()
    Dim songUri As New Uri("someSong.mp3", UriKind.RelativeOrAbsolute)
    Dim song = Microsoft.Xna.Framework.Media.PhoneExtensions.MediaLibraryExtensions.SaveSong(ml, songUri, metaData, Microsoft.Xna.Framework.Media.PhoneExtensions.SaveSongOperation.CopyToLibrary)

所以我可以将歌曲加载到我的手机歌曲中心(Lumia 920),但是当我点击非歌曲时它会给出错误:c00d36c4。在保存期间,流似乎被破坏了。

我正在尝试保存的歌曲在应用程序项目中,包含构建操作“内容”和“不要复制”。

在WP Emulator上也是如此,即使我使用另一个mp3文件也是如此。

我找不到任何关于SaveSong方法的官方文档,你能帮助我吗?

1 个答案:

答案 0 :(得分:0)

解决了这个问题。它无法正确复制整个流。我切换到[Stream].CopyTo方法,然后工作。