/// <summary> /// Create a new instance of SongChangedEventArgs for a specified song /// </summary> /// <param name="song">The current song</param> public SongChangedEventArgs(Song song) { Song = song; }
/// <summary> /// Initialise the Winamp class. Called from the constructor /// </summary> private void Init() { // Let's set up debugging, if we're in debug mode! #if DEBUG string debugDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string debugFile = Path.Combine(debugDir, "winamp-cs-debug.txt"); Debug.Listeners.Add(new TextWriterTraceListener(new StreamWriter(debugFile, true))); Debug.AutoFlush = true; Debug.WriteLine("hWnd: " + _WinampWindow); #endif // Start with a blank "currently playing" song CurrentSong = new Song(); // Update the song data UpdateSongData(); // And now, let's set up our subclassing. We can only do this if we're // "in process", so let's bail if we're not. if (!_InProcess) { // TODO: This should not be a messagebox. This is just for debugging. System.Windows.Forms.MessageBox.Show("Not running 'in process', certain features will not work!"); return; } // Here's our delegate _WinampWndProc = new Win32.Win32WndProc(WinampWndProc); // Make sure it doesn't get garbage collected GC.KeepAlive(_WinampWndProc); // Let's go ahead and set the new one, saving the old one _OldWinampWndProc = Win32.SetWindowLong(_WinampWindow, Win32.GWL_WNDPROC, _WinampWndProc); Debug.WriteLine("Subclassed Winamp window (old proc = " + _OldWinampWndProc + ", new proc = " + _WinampWndProc +")"); }
// TODO: Version string #endregion /// <summary> /// Update the data about the currently playing song /// </summary> private void UpdateSongData() { // Get the current title //string title = SendIPCCommandString(IPCCommand.GetTitle); // Get string filename = SendIPCCommandString(IPCCommand.GetFilename); Debug.WriteLine("Filename = " + filename); // Here's all our data. bool hasMetadata = true; string title = GetMetadata(filename, "title"); string artist = ""; string year = ""; string album = ""; // If the title is blank, we don't have any metadata :( // Better just get whatever Winamp gives us as the "title", and save // that. if (String.IsNullOrEmpty(title)) { title = SendIPCCommandString(IPCCommand.GetTitle); hasMetadata = false; } // Only update the data if it's changed /* TODO: This is a hack. What if the title is the same, but the * artist or album is different? It won't be counted as a change * I need to think of a better way of doing this. */ if (CurrentSong.Title == title) return; // Get all our extra metadata, if we can if (hasMetadata) { artist = GetMetadata(filename, "artist"); year = GetMetadata(filename, "year"); album = GetMetadata(filename, "album"); } // Save the new song Song song = new Song{ HasMetadata = hasMetadata, Filename = filename, Title = title, Artist = artist, Album = album, Year = year }; CurrentSong = song; // Invoke the "song changed" method if (SongChanged != null) SongChanged(this, new SongChangedEventArgs(song)); }
private void UpdateData(Song song) { // Update the labels lblHasMetadata.Text = "Has Metadata? " + (song.HasMetadata ? "Yes" : "No"); lblTitle.Text = "Title: " + song.Title; lblArtist.Text = "Artist: " + song.Artist; lblAlbum.Text = "Album: " + song.Album; lblFilename.Text = "Filename: " + song.Filename; lblYear.Text = "Year: " + song.Year; }