/// <summary> /// 播放器初始化 /// </summary> public void Initialize() { if (IsInitialized) { return; } Debug.WriteLine(DateTime.Now + " 播放器核心初始化中"); //bool lastTimeLoggedOn = Settings.LastTimeLoggedOn; ThreadPool.QueueUserWorkItem(new WaitCallback((state) => { ////如果用户上次退出软件时处于未登录状态,则启动时不更新登录状态 //if (lastTimeLoggedOn) //{ // string file; // while (true) // { // Debug.WriteLine(DateTime.Now + " 刷新豆瓣FM主页……"); // file = new ConnectionBase().Get("http://douban.fm/"); // Debug.WriteLine(DateTime.Now + " 刷新完成"); // if (!string.IsNullOrEmpty(file)) // { // break; // } // TakeABreak(); // } // //更新用户的登录状态 // UserAssistant.Update(file); //} //检查用户登录状态是否已过期。 bool expired = !string.IsNullOrEmpty(UserAssistant.Settings.User.Token); UserAssistant.Initialize(); expired = expired && string.IsNullOrEmpty(UserAssistant.Settings.User.Token); var channelInfo = GetChannelInfo(); Dispatcher.Invoke(new Action(() => { /** * 当上次退出时是登录状态,但之后在浏览器里注销后,再打开软件会显示未登录, * 但Cookie还在,如果不清除Cookie,第一次登录会失败,清除后第一次登录也能成功 * */ //if (UserAssistant.CurrentState != Core.UserAssistant.State.LoggedOn) // UserAssistant.LogOff(); ChannelInfo = channelInfo; RaisePlayRecordChangedEvent(); IsInitialized = true; Debug.WriteLine(DateTime.Now + " 播放器核心初始化完成"); if (expired) { RaiseUserExpiredEvent(); } //选择一个频道 ChooseChannelAtStartup(); })); })); }
public Player() : base() { LoadSettings(); UserAssistant = new UserAssistant(); UserAssistant.Settings = Settings; ChannelSearch = new ChannelSearch(Settings); DownloadSearch.Settings = Settings; //加红心功能始终启用 IsLikedEnabled = true; //歌曲改变时更新红心状态 CurrentSongChanged += new EventHandler((o, e) => { if (CurrentSong != null) { IsLiked = CurrentSong.Like; } }); UserAssistant.CurrentStateChanged += (o, e) => { //更新IsNeverEnabled IsNeverEnabled = UserAssistant.CurrentState == UserAssistant.State.LoggedOn || UserAssistant.CurrentState == UserAssistant.State.LoggingOff; switch ((UserAssistant.State)e.NewValue) { case UserAssistant.State.LoggedOn: RaisePlayRecordChangedEvent(); break; case UserAssistant.State.LoggedOff: if (CurrentChannel != null && CurrentChannel.IsPersonal && !CurrentChannel.IsSpecial) { CurrentChannel = ChannelInfo.Public.First(); } break; } }; //获取播放列表失败后引发事件 PlayList.GetPlayListFailed += (o, e) => Dispatcher.Invoke(new Action(() => RaiseGetPlayListFailedEvent(e))); }
public Player() : base() { LoadSettings(); UserAssistant = new UserAssistant(); UserAssistant.Settings = Settings; ChannelSearch = new ChannelSearch(Settings); DownloadSearch.Settings = Settings; //加红心功能始终启用 IsLikedEnabled = true; //歌曲改变时更新红心状态 CurrentSongChanged += new EventHandler((o, e) => { if (CurrentSong != null) { IsLiked = CurrentSong.Like; } }); UserAssistant.CurrentStateChanged += (o, e) => { //更新IsNeverEnabled IsNeverEnabled = UserAssistant.CurrentState == UserAssistant.State.LoggedOn || UserAssistant.CurrentState == UserAssistant.State.LoggingOff; switch ((UserAssistant.State) e.NewValue) { case UserAssistant.State.LoggedOn: RaisePlayRecordChangedEvent(); break; case UserAssistant.State.LoggedOff: if (CurrentChannel != null && CurrentChannel.IsPersonal && !CurrentChannel.IsSpecial) CurrentChannel = ChannelInfo.Public.First(); break; } }; //获取播放列表失败后引发事件 PlayList.GetPlayListFailed += (o, e) => Dispatcher.Invoke(new Action(() => RaiseGetPlayListFailedEvent(e))); }