我有一个问题,似乎我对我的ApplicationSettings做的更改没有更新我的AudioPlayerAgents ApplicationSettings应该是相同的?!
我的程序看起来像这样:
在OnNavigatedTo的MainPage.xaml.cs中,我创建了两个音频文件数组
Audio[] aud = new Audio[2];
Audio[] aud1 = new Audio[2];
aud[0] = new Audio(new Uri("1.mp3", UriKind.Relative),
"Test1",
"Test1",
new Uri("Images/Covers/0000000018724345_256x256_large.jpg", UriKind.Relative));
aud[1] = new Audio(new Uri("2.mp3", UriKind.Relative),
"Test2",
"Test2",
new Uri("Images/Covers/0000000018698018_256x256_large.jpg", UriKind.Relative));
aud1[0] = new Audio(new Uri("3.mp3", UriKind.Relative),
"Test3",
"Test3",
new Uri("Images/Covers/0000000018465020_256x256_large.jpg", UriKind.Relative));
aud1[1] = new Audio(new Uri("http://traffic.libsyn.com/wpradio/WPRadio_29.mp3", UriKind.Absolute),
"Episode 29",
"Windows Phone Radio",
new Uri("Images/Covers/0000000018844939_256x256_large.jpg", UriKind.Relative));
然后我在ApplicationSettings中保存其中一个数组
IsolatedStorageSettings.ApplicationSettings["tracklist"] = aud;
IsolatedStorageSettings.ApplicationSettings.Save();
然后我关闭并启动BackgroundAudioPlayer.
BackgroundAudioPlayer.Instance.Close();
BackgroundAudioPlayer.Instance.Play();
在我的AudioPlayer中,我正在加载以前保存的ApplicationSettings,它工作正常.
Audio[] aud;
IsolatedStorageSettings.ApplicationSettings.TryGetValue<Audio[]>("tracklist", out aud);
但是当我后来想要将MainPage.xaml.cs中的ApplicationSettings替换为另一个数组时
IsolatedStorageSettings.ApplicationSettings["tracklist"] = aud1;
IsolatedStorageSettings.ApplicationSettings.Save();
并在我的AudioPlayer中再次加载值,我的ApplicationSettings中仍然存在旧值,AudioPlayerAgent和MainPage应该使用相同的ApplicationSettings吗?事实上,第一次保存并可用于AudioPlayerAgent,所以我错过了什么?
我的Audio类看起来像这样
[DataContractAttribute]
public class Audio
{
[DataMember]
public Uri TrackUrl { get; set; }
[DataMember]
public string Title { get; set; }
[DataMember]
public string Artist { get; set; }
[DataMember]
public Uri CoverURL { get; set; }
public Audio(Uri trackUrl, string title, string artist, Uri coverUrl)
{
TrackUrl = trackUrl;
Title = title;
Artist = artist;
CoverURL = coverUrl;
}
}
最佳答案 我觉得你有另一个程序集/ dll中的MusicPlayerAgent.如果这样做会解释问题,因为每个程序集都有自己的独立存储.如果他们在同一个集会中,我不知道为什么那不起作用,因为我自己在几乎所有我的手机应用程序中都这样做.这是我读过的隔离存储的最佳读物.如果有什么我希望链接是一个很好的阅读.
Link