6

を使用するインターネット ラジオ アプリがありますBackgroundAudioPlayer

インターネット ラジオ ステーションの API から取得された BAP の現在再生中のトラックのトラック タイトルを更新する Audio Playback Agent のタイマーが必要です。

オーディオ再生エージェントにa を追加するDispatcherTimerと、クロススレッド例外が発生し、次を使用します。

Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // Code
            });

うまくいきませんでした。

アプリ自体に更新コードを配置すると、ユーザーがアプリから離れたときに更新が停止するため、ここにコードが必要です (Windows 8 の動作とは大きく異なります)。

スケジュールされたエージェントは 30 分ごとに 1 回しか実行されない (IIRC) ため、使用できません。

これは可能ですか、それとも Windows Phone ではできませんか?

4

3 に答える 3

0

私はあなたを助けることができる質問を見つけました:Windows Phone 8でバックグラウンドでタイマーを実行する方法は?

「タイトル」が最後の既知のタイトルと異なるかどうかをx秒ごとにチェックするタイマーを設定すると、この情報をそれに送り返すことができます。

これは、タイマーのコードである可能性があります。

これらを宣言します。

string _newValue = string.Empty;
string _currentValue = string.Empty;
AudioTrack _tempTrack = null;

これをタイマーのティックとして設定します

if (this.BackgroundAudioPlayer != null)
{
   if (this.BackgroundAudioPlayer.Instance != null)
   {
       if (this.BackgroundAudioPlayer.Instance.Track != null)
       {
           this._newValue= yourAPI.GetTitleOfTrack();

           try
           {
               /* First try to get the current Track as own Var */
               this._tempTrack = this.BackgroundAudioPlayer.Instance.Track;
               if (this._tempTrack != null)
               {
                  /* Then Read the .Tag Value from it, save to _currentValue */
                  if (this._tempTrack.Tag != null) 
                  { this._currentValue = this._tempTrack.Tag.ToString(); }
                  else
                  { this._currentValue = string.Empty; }

                  /* Compare */
                  if (this._currentValue != this._newValue)
                  {
                     /* Edit the Track Tag from your original BAP */
                     this.BackgroundAudioPlayer.Instance.Track.Tag = this._newValue;
                  }
               }
           }
           catch(Exception ex)
           {
               /* if something Crashes you can save the exception error for protocol */
           }
       }
   }
}

覚えておいてください: "yourAPI.GetTitleOfTrack()"-Function をこれから API の実際の関数呼び出しに変更します。

于 2016-01-08T13:02:35.117 に答える
-1

以下の track タグのように、バックグラウンド オーディオ プレーヤー エージェントの情報を更新することを検討しましたか。

string newTag = "whatever you need to show";
AudioTrack track = BackgroundAudioPlayer.Instance.Track;
track.BeginEdit();
track.Tag = newTag;
track.EndEdit();

必要に応じて、アプリケーションによってフロントエンドでそのタグを読み取りますか?

于 2014-06-11T09:15:26.970 に答える