Silverlight 如何通过URI(WP7)访问IsolatedStorage中下载的声音?

Silverlight 如何通过URI(WP7)访问IsolatedStorage中下载的声音?,silverlight,windows-phone-7,uri,isolatedstorage,alarm,Silverlight,Windows Phone 7,Uri,Isolatedstorage,Alarm,我基本上下载了一个文件名custom.mp3到我的isolatedstorage中,我可以通过isolatedstorage explorer查看它 这里的问题是。。。如何通过URI访问特定的custom.mp3 到目前为止我得到了这个。。但我想知道为什么它不起作用: alarm.Sound = new Uri("isostore:/custom.mp3", UriKind.Absolute); 你的道路错了。您的代码没有其他问题。如果需要进一步帮助,请首先发布保存mp3文件的代码。为便于阅读

我基本上下载了一个文件名custom.mp3到我的isolatedstorage中,我可以通过isolatedstorage explorer查看它

这里的问题是。。。如何通过URI访问特定的custom.mp3

到目前为止我得到了这个。。但我想知道为什么它不起作用:

alarm.Sound = new Uri("isostore:/custom.mp3", UriKind.Absolute);

你的道路错了。您的代码没有其他问题。如果需要进一步帮助,请首先发布保存mp3文件的代码。

为便于阅读,存储mp3的代码如下所示

string alarmfile = "custom.mp3";
isolatedStorageFileStream = new IsolatedStorageFileStream(alarmfile,FileMode.Create,isolatedStorageFile);
long songfilelength = (long) e.Result.Length;
byte[] songbyte = new byte[songfilelength];
e.Result.Read(songbyte, 0, songbyte.Length);
isolatedStorageFileStream.Write(songbyte, 0, songbyte.Length);
isolatedStorageFileStream.Flush();

只有打包在XAML中的文件才能用作报警声音:

评论

声音URI必须指向应用程序的.xap中打包的文件 文件不支持独立存储。当警报启动时, 声音会安静地播放,然后逐渐增大音量。 无法修改此行为

发件人:


您是否尝试过新的Uri/custom.mp3,UriKind.Relative;我不知道这是否有效,但值得一试。/custom.mp3 URI只有在编译时将文件与应用程序一起附加时才有效。但是谢谢你的回答:我的意思是我试过了,但它不起作用。。。只有当我和我的应用程序一起编译时,/custom.mp3才有效…是的,你是对的,它必须是项目的一部分才能使用这个uri.Urm。。代码如下:string alarmfile=custom.mp3;isolatedStorageFileStream=新建IsolatedStorageFileStreamalarmfile,FileMode.Create,isolatedStorageFile;long songfilelength=长e.Result.Length;byte[]songbyte=新字节[songfilelength];e、 Result.Readsongbyte,0,songbyte.Length;isolatedStorageFileStream.Writesongbyte,0,songbyte.Length;isolatedStorageFileStream.Flush;