protected override void OnNavigatedFrom(NavigationEventArgs e) { trigger.Set(); base.OnNavigatedFrom(e); if (LyricTimer != null) { LyricTimer.Cancel(); } trigger = null; CurrentSong = null; lyric = null; lyrics = null; }
public ActionResult Detail(int id, String mainbody, int Score) { var com = new Comment() { DocumentId = id, MainBody = mainbody, Score = Score }; db.Comment.Add(com); db.SaveChanges(); Document doc = db.Document.FirstOrDefault(m => m.Id == id); ILrcFile lrcFile = LrcFile.FromText(doc.Lyrics); ViewBag.Lrcs = lrcFile; ViewData.Model = doc; // return View(); // return Content("true"); // return Json(json); return(Json(new { status = 200, message = "提交成功", score = com.Score, mainbody = com.MainBody })); }
public async Task genLrc() { string result = null; try { result = await LrcHelper.Fetch(await LrcHelper.isLrcExist(CurrentSong), CurrentSong); } catch (System.Net.WebException) { this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => { var loader = new Windows.ApplicationModel.Resources.ResourceLoader(); loader.GetString("WebExceptionText"); ErrText.Text = "没有网络连接"; })); } if (result == null) { lyric = null; lyrics = null; return; } else { var stream = await FileHelper.ReadFileasString(result); try { lyric = LrcFile.FromText(stream); lyrics = new List<LrcModel>(); foreach (var item in lyric.Lyrics) { lyrics.Add(new LrcModel(item)); } } catch (FormatException e) { try { var strings = e.Message.Split('\''); string s = strings[1].Substring(strings[1].IndexOf(':') + 1); s = s.TrimEnd('0'); int j = stream.IndexOf(s); int start, end; for (int i = j; ; i--) { if (i <= 0 || stream[i] == '\n') { start = i; for (j = stream.IndexOf(s); ; j++) { if (j >= stream.Length || stream[j] == '\n') { end = j; break; } } break; } } StringBuilder sb = new StringBuilder(stream.Substring(0, start)); sb.Append(stream.Substring(end)); s = sb.ToString(); await FileHelper.SaveFile(s, result); lyric = LrcFile.FromText(s); lyrics = new List<LrcModel>(); foreach (var item in lyric.Lyrics) { lyrics.Add(new LrcModel(item)); } } catch (Exception) { lyric = null; lyrics = null; } } trigger.Set(); } }
private async Task FetchLrc() { try { var uri = CurrentSong.Title + "-" + CurrentSong.Artists[0] + "-" + CurrentSong.Album + ".lrc"; lyric = LrcFile.FromText(await FileHelper.ReadFileasString(uri)); lyrics = new List<LrcModel>(); foreach (var item in lyric.Lyrics) { lyrics.Add(new LrcModel(item)); } trigger.Set(); } catch (Exception) { try { await genLrc(); trigger.Set(); } catch (Exception) { if (trigger != null) { trigger.Set(); } } } }
public void SetLrcFile(ILrcFile lrcFile) { this.lrcFile = lrcFile; }
private void TryAnalyzeLyrics(string lyrics) { if (!string.IsNullOrEmpty(lyrics)) { try { LyricModel = LrcFile.FromText(lyrics); } catch { } } }