Windows音频播放代理更新标题和艺术家直播

时间:2014-02-05 20:19:23

标签: c# windows-phone-7 background-audio

如何在播放时更新Windows音频播放代理属性,如标题和艺术家,直播。我想每20秒更新一次标题而不停止播放的音乐?请帮忙。我尝试了这个,但它每20秒停止和重放一次很烦人。这是代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.BackgroundAudio;
using System.Threading;
using System.Windows.Threading;

namespace PhoneApp2
{
    public partial class MainPage : PhoneApplicationPage
    {
        DispatcherTimer timer = new DispatcherTimer();
        string Artist;
        string Song;
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, RoutedEventArgs e)
        {

            timer.Interval = TimeSpan.FromSeconds(20);
            timer.Start();
            timer.Tick += timer_Tick;
        }

        void timer_Tick(object sender, EventArgs e)
        {
            WebClient client = new WebClient();
            client.Encoding = System.Text.Encoding.UTF8;
            client.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.Now.ToString();
            client.DownloadStringAsync(new Uri("http://air-online2.hitfm.md/status_hitfm.xsl"));
            client.DownloadStringCompleted += client_DownloadStringCompleted;
        }

        void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            string[] FullTitle = e.Result.Substring(166).Split('-');
            Artist= FullTitle[0];

            if(Artist.Contains(":"))
            {
               Artist=FullTitle[0].Replace(":",string.Empty);
            }
            Song = FullTitle[1].Replace(" ", string.Empty);
            if (BackgroundAudioPlayer.Instance.PlayerState != PlayState.Playing)
            {
                BackgroundAudioPlayer.Instance.Track = new AudioTrack(new Uri("http://air-online2.hitfm.md/hitfm.mp3"), Artist, Song, null, null);
                BackgroundAudioPlayer.Instance.Play();
            }
            else
            {
                BackgroundAudioPlayer.Instance.Track = new AudioTrack(new Uri("http://air-online2.hitfm.md/hitfm.mp3"), Artist, Song, null, null);

            }
        }
    }
}

0 个答案:

没有答案