0

这是我在 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 方法的官方文档,你能帮我吗?

4

1 回答 1

0

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

于 2013-01-22T14:18:14.190 回答