Question

Here's the code I found on MSDN forum:

    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)

So I'm able to load the song into my phone song hub (Lumia 920), but when I tap non the song it gives error: c00d36c4. It seems the stream get corrupted during the saving.

The song I'm trying to save is in the app project with build action "Content" and "Do not copy".

The same happens on WP Emulator or even if I use another mp3 file.

I couldn't find any official documentation about SaveSong method, can you help me?

Was it helpful?

Solution

Solved the problem. It wasn't able to copy the whole stream correctly. I switched to [Stream].CopyTo method and then worked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top