4

ApplicationSettings に加えた変更が、AudioPlayerAgents ApplicationSettings で更新されていないように見えるという問題がありますが、これは同じである必要があります。

私のプログラムは次のようになります。

OnNavigatedTo の MainPage.xaml.cs で、オーディオ ファイルの 2 つの配列を作成しています。

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

次に、この配列の 1 つを 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 で使用できるようになるので、何が欠けているのでしょうか?

私のオーディオクラスは次のようになります

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

3 に答える 3

1

別のアセンブリ/dll に MusicPlayerAgent があるように感じます。各アセンブリには独自の分離ストレージがあるため、そうすると問題が説明されます。それらが同じアセンブリにある場合、私が持っているほとんどすべての電話アプリで自分でそれを行うので、なぜそれが機能しないのかわかりません。これは、私が読んだ分離ストレージに関する最高の読み物です。どちらかといえば、リンクがよく読まれていることを願っています。リンク

于 2011-11-12T18:41:37.727 に答える
1

私は同じ問題に直面しました。私には、IsolatedStorageSettings が静的なものに「キャッシュ」されているように思えます。つまり、バックグラウンド プロセスとフォアグラウンド プロセスの両方が実行されるまで、それぞれが独自のバージョンの IsolatedStorageSettings を使用します。元のコードをさらに深く掘り下げると、次のことがわかりました。

public sealed class IsolatedStorageSettings : ...
{
    private static IsolatedStorageSettings s_appSettings;
    ...
    public static IsolatedStorageSettings ApplicationSettings
    {
        get
        {
            if (IsolatedStorageSettings.s_appSettings == null)
            {
                IsolatedStorageSettings.s_appSettings = new IsolatedStorageSettings(false);
            }
            return IsolatedStorageSettings.s_appSettings;
        }
    }
    ...
    private IsolatedStorageSettings(bool useSiteSettings)
    {
        if (useSiteSettings)
        {
            throw new NotSupportedException();
        }
        this._appStore = IsolatedStorageFile.GetUserStoreForApplication();
        this.Reload();
    }

ここで、IsolatedStorageSettings が実際にはメソッド Reload で (静的変数であるため) プロセスごとに 1 回だけ読み込まれることがわかります。コードを調べたところ、Reload が呼び出される場所は他に見つかりませんでした。

同じ問題に直面しているすべての人に、「独自の」設定ストレージを使用して、AudioAgent とアプリの間で動的データを共有することを提案できます ( Phiiiiiiippが最後のコメントで述べたように)

私の知る限り、ベスト プラクティスは AudioTrack.Tag プロパティを使用することです。

于 2013-12-09T06:39:01.860 に答える