Search code examples
windows-phone-7serializationisolatedstorageapplication-settingsbackground-agent

Is it possible to have different IsolatedStorageSettings.ApplicationSettings?


I have the problem that it seems like the changes I do to my ApplicationSettings are not updated in my AudioPlayerAgents ApplicationSettings which should be the same ?!

My program looks like this:

In my MainPage.xaml.cs in the OnNavigatedTo I am creating two arrays of Audio Files

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));

Then I am saving one of this arrays in the ApplicationSettings

IsolatedStorageSettings.ApplicationSettings["tracklist"] = aud;
IsolatedStorageSettings.ApplicationSettings.Save();

Then I am closing and starting the BackgroundAudioPlayer.

BackgroundAudioPlayer.Instance.Close();
BackgroundAudioPlayer.Instance.Play();

In my AudioPlayer I am loading the previously saved ApplicationSettings which works fine.

Audio[] aud;
IsolatedStorageSettings.ApplicationSettings.TryGetValue<Audio[]>("tracklist", out aud);

But when I later want to replace the ApplicationSettings in my MainPage.xaml.cs with the other array

  IsolatedStorageSettings.ApplicationSettings["tracklist"] = aud1;
  IsolatedStorageSettings.ApplicationSettings.Save();

And load the values again in my AudioPlayer there are still the old values in my ApplicationSettings, both the AudioPlayerAgent and the MainPage should use the same ApplicationSettings right ? In fact the first time it is saved and available to the AudioPlayerAgent, so what am I missing ?

My Audio class looks like this

[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;
    }
} 

Solution

  • I have a feeling that you have the MusicPlayerAgent in another assembly/dll. If you do that would explain the problem since each assembly has its own isolated storage. If they are in the same assembly I dont have any idea why that wouldnt work since I do that myself in almost all my phone apps I have. Here is the best read on Isolated Storage I have read. If anything I hope the link is a good read. Link