private void Player_StreamChanged(object sender, Common.StreamChangedEventArgs e) { string l_lines; clock.Clear(); t_lines.Clear(); var fileName = PrestoSDK.PrestoService.Player.CurrentMusic.Path; lines = File.ReadAllLines(Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName)) + ".txt"); for (int i = 0; i < lines.Length; i++) { t_lines.Add(new List <string>()); } for (int i = 3; i < 6; i++) { if ((Convert.ToInt32(lines[3].Substring(1, 2)) * 6000 + Convert.ToInt32(Convert.ToSingle(lines[3].Substring(4, 5)) * 100) == (Convert.ToInt32(lines[i].Substring(1, 2)) * 6000) + Convert.ToInt32(Convert.ToSingle(lines[i].Substring(4, 5)) * 100))) { arr = (i - 3); } else { break; } } count = 3; a = arr + 1; plus = 0; for (int i = 3; i < lines.Length / (arr + 1); i++) { for (int j = 0; j <= arr; j++) { t_lines[i - 3].Add(lines[count].ToString()); count++; } if (arr == 0) { l_lines = lines[i].ToString(); clock.Add(Convert.ToInt32(l_lines.Substring(1, 2)) * 6000 + Convert.ToInt32(Convert.ToSingle(l_lines.Substring(4, 5)) * 100)); } else { l_lines = lines[3 + (plus * a)].ToString(); clock.Add(Convert.ToInt32(l_lines.Substring(1, 2)) * 6000 + Convert.ToInt32(Convert.ToSingle(l_lines.Substring(4, 5)) * 100)); } plus++; } MessageBox.Show(fileName.ToString()); tt.Text = (Path.GetFileNameWithoutExtension(PrestoSDK.PrestoService.Player.CurrentMusic.Path)); }
private void Player_StreamChanged(object sender, Common.StreamChangedEventArgs e) { //GC 강제 실행 System.GC.Collect(2, GCCollectionMode.Forced); System.GC.WaitForFullGCComplete(); if (IsThisWindowShow == true || _lyricsLarge.IsThisWindowShow == false) { this.IsThisWindowShow = true; this.Show(); } albumartManager.AlbumArtSearch(); albumArtImage.ImageSource = albumartManager.AlbumArtImageSource; _lyricsLarge.SetAlbumArtImage(albumartManager.AlbumArtImageSource); }
private void Player_StreamChanged(object sender, Common.StreamChangedEventArgs e) { this.Show(); lyricsManager.StreamChanged(); //GC 강제 실행 System.GC.Collect(2, GCCollectionMode.Forced); System.GC.WaitForFullGCComplete(); if (PrestoSDK.PrestoService.Player.CurrentMusic.Title == null) { string fileName = Path.GetFileNameWithoutExtension(lyricsManager.CurrentMusic); PrestoSDK.PrestoService.Player.CurrentMusic.Title = fileName; } }
// 재생중인 음악이 바뀌면 private void Player_StreamChanged(object sender, Common.StreamChangedEventArgs e) { // 큰 플레이어가 실행중이고, 숨겨진 상태라면 if (IsThisWindowShow == true) { this.Show(); } lyricsManager = null; lyricsManager = new LyricsManager(); lyricsManager.LyricsListIndex = 0; // 현재 바뀐 음악에 대한 가사 처리 lyricsManager.StreamChanged(); // 재바인딩 lyricsList.ItemsSource = lyricsManager.GetLyricsData(); isAutoLyricsIndexChange = true; lyricsList.SelectedIndex = 0; lyricsList.ScrollIntoView(lyricsList.Items[0]); }
private void Player_StreamChanged(object sender, Common.StreamChangedEventArgs e) { starting = true; //첫 재생 Topmost = true; // 스트림이 바뀔 때 마다 가사 창 맨 앞으로 가져오기 Topmost = false; //가사 초기화 textLyrics.Text = null; LyricPanel.Children.Clear(); //패널 초기화 splitData = new List <Tuple <TimeSpan, string> >(); //파싱 데이터 리스트 초기화 songInfo = " "; //곡 정보 초기화 //lrc파일 경로 변경 var fileName = PrestoSDK.PrestoService.Player.CurrentMusic.Path; var lrcName = Path.GetFileNameWithoutExtension(fileName) + ".lrc"; //Image 파일 변경 String imgPath = "C:\\Users\\Admin\\LyricsProject\\Presto.SWCamp.Lyrics\\" + "Assets\\" + Path.GetFileNameWithoutExtension(fileName) + ".jpg"; Uri imageUri = new Uri(imgPath, UriKind.Absolute); BitmapImage imageBitmap = new BitmapImage(imageUri); Image myImage = new Image(); myImage.Source = imageBitmap; songImg.ImageSource = myImage.Source; var path = Path.Combine(Path.GetDirectoryName(fileName), lrcName); //가사 데이터 읽어 오기 var lines = File.ReadAllLines(path); string singer = null; //파트 저장할 변수 tb = new TextBlock[lines.Length]; //가사 한줄 한줄의 배열 생성 //곡 정보 저장 songInfo += "가수 : " + (lines[0].Substring(4)).Split(']').First() + '\n'; songInfo += "제목 : " + (lines[1].Substring(4)).Split(']').First() + '\n'; songInfo += "앨범 : " + (lines[2].Substring(4)).Split(']').First() + '\n'; for (int i = 3; i < lines.Length; i++) { tb[i] = new TextBlock(); //가사 한줄 생성 string[] data = lines[i].Split(']'); //가사 한줄을 ']' 단위로 스플릿 if (data.Length == 2) //파트 지정이 없는 부분 { data[1] = singer + data[1] + '\n'; //이전 파트를 붙임 tb[i].Text = data[1]; //가사 한줄(텍스트 박스)에 가사 데이터 지정 } else if (data.Length == 3) //파트 지정이 있는 부분 { singer = '(' + data[1].Substring(1).Trim() + ") "; data[1] = singer + data[2] + '\n'; tb[i].Text = data[1]; } TimeSpan time = TimeSpan.ParseExact(data[0].Substring(1).Trim(), @"mm\:ss\.ff", CultureInfo.InvariantCulture); //시간 데이터 string lyric = data[1]; //가사 데이터 splitData.Add(new Tuple <TimeSpan, string>(time, lyric)); //가사 한줄 데이터 추가 } //노래 재생시간 타이머 var timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(100) }; timer.Tick += Timer_Tick; timer.Start(); }
private void Player_StreamChanged(object sender, Common.StreamChangedEventArgs e) { isMultilineLyrics = false; String[] lyricsRaw; String filePath = PrestoSDK.PrestoService.Player.CurrentMusic.Path; //앞의 노래 가사 지우기 foreach (var lyrics in lyricsTextBlock) { lyrics.Text = ""; } if (timer != null) { timer.Stop(); } timeline = new List <LyricsPair>(); text_full_lyrics.Text = ""; //전체 가사 모드 해제 if (isFullLyricsViewer) { Button_full_lyrics_Click(null, null); } //윈도우폼 배경을 현재 앨범 이미지로 변경 String albumPicture = PrestoSDK.PrestoService.Player.CurrentMusic.Album.Picture; ImageBrush BackPicture = new ImageBrush(new BitmapImage(new Uri(albumPicture))) { Opacity = 0.2, Stretch = Stretch.UniformToFill }; this.Background = BackPicture; // 가사 파일 읽기 currentLyricIndex = 0; try { lyricsRaw = File.ReadAllLines(filePath.Substring(0, filePath.Length - 4) + ".lrc"); isLyricsFileExist = true; } catch (System.IO.FileNotFoundException) { isMultilineLyrics = false; isLyricsFileExist = false; lyricsRaw = new string[] { }; } finally { if (isLyricsFileExist) { foreach (var lyrics in lyricsTextBlock) { lyrics.Visibility = Visibility.Visible; } } else // 가사 파일 존재하지 않을 시 컨트롤 숨기기 { this.Title = "Presto Floating Lyrics"; foreach (var lyrics in lyricsTextBlock) { lyrics.Visibility = Visibility.Collapsed; } lyricsTextBlock[1].Text = "가사 파일 없음"; lyricsTextBlock[1].Visibility = Visibility.Visible; if (!isFullLyricsViewer) { button_full_lyrics.Visibility = Visibility.Hidden; } } } // 가사 파싱 foreach (var line in lyricsRaw) { if (line[1] > 64) // ASCII.64 == @ { continue; } int threshold = line.IndexOf(']'); // 플레이 타임 추출 String timeRaw = line.Substring(1, threshold - 1); var timeSplited = timeRaw.Split(new char[] { ':', '.' }); TimeSpan timeSpan = new TimeSpan(0, 0, int.Parse(timeSplited[0]) , int.Parse(timeSplited[1]) , int.Parse(timeSplited[2]) * 10); // 가사 추출 if (timeline.Count > 0 && timeline[timeline.Count - 1].timeline.TotalMilliseconds == timeSpan.TotalMilliseconds) { timeline[timeline.Count - 1].lyrics += "\n" + line.Substring(threshold + 1); isMultilineLyrics = true; } else { timeline.Add(new LyricsPair(timeSpan, line.Substring(threshold + 1))); } } //전체 가사 파싱 foreach (var line in lyricsRaw) { if (line[1] > 64) // ASCII.64 == @ { text_full_lyrics.Text = ""; continue; } text_full_lyrics.Text += line.Substring(line.IndexOf(']') + 1) + "\n"; } //다국어 가사이면 창크기를 늘리고 위치를 위로 조금 올림 if (!isFullLyricsViewer) { if (isMultilineLyrics) { lyricsWindow.Height = WINDOW_HEIGHT_MULTILINE; if (lyricsWindow.Top + lyricsWindow.Height > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height) { Origin_WindowTop = lyricsWindow.Top; lyricsWindow.Top -= (this.Top + this.Height) - System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; MultilineLyrics_Check = true; } } else { lyricsWindow.Height = WINDOW_HEIGHT_NORMAL; if (MultilineLyrics_Check) { lyricsWindow.Top = Origin_WindowTop; MultilineLyrics_Check = false; } } } // 타이밍 if (isLyricsFileExist) { timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(10) }; timer.Tick += Timer_Tick; timer.Start(); } }