在Windows Phone 7模拟器中添加更多音乐?

时间:2010-11-26 13:58:22

标签: windows-phone-7 xna

模拟器有3首歌曲,但不足以确保我正在处理的歌曲选择代码将比3首歌曲管理更多。

所以只是想知道它是否可能?

2 个答案:

答案 0 :(得分:2)

不幸的是,没有办法将歌曲添加到模拟器中 你必须使用真实设备来测试它。

答案 1 :(得分:1)

实际上您可以使用应用程序执行此操作:

Uri file = new Uri("Assets/Happy.mp3", UriKind.Relative);

//copy file to isolated storage
var myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
var fileStream = myIsolatedStorage.CreateFile("someSong.mp3");
var resource = Application.GetResourceStream(file);
int chunkSize = 4096;
byte[] bytes = new byte[chunkSize];
int byteCount;
while ((byteCount = resource.Stream.Read(bytes, 0, chunkSize)) > 0)
{
    fileStream.Write(bytes, 0, byteCount);
}
fileStream.Close();
Microsoft.Xna.Framework.Media.PhoneExtensions.SongMetadata metaData = 
    new Microsoft.Xna.Framework.Media.PhoneExtensions.SongMetadata();
metaData.AlbumName = "Some Album name";
metaData.ArtistName = "Some Artist Name";
metaData.GenreName = "test";
metaData.Name = "someSongName";

var ml = new MediaLibrary();
Uri songUri = new Uri("someSong.mp3", UriKind.RelativeOrAbsolute);
var song = Microsoft.Xna.Framework.Media.PhoneExtensions.MediaLibraryExtensions.SaveSong(ml, songUri, metaData, Microsoft.Xna.Framework.Media.PhoneExtensions.SaveSongOperation.CopyToLibrary);