//======================================================================================== // Constructor //======================================================================================== /// <summary> /// Initialize a new iTunesAppClass safe wrapper. /// </summary> public Controller() : base() { InitializeHost(); this.engine = LyricEngine.CreateEngine(); this.engine.LyricsUpdated += new TrackHandler(DoLyricsUpdated); this.engine.LyricsProgressReport += new LyricEngineProgress(DoLyricsProgressReport); if (this.track != null) { if (!this.track.HasLyrics && NetworkStatus.IsAvailable) { this.engine.RetrieveLyrics(this.track); } } this.librarian = Librarian.Create(this); this.timer = new Timer(1000); this.timer.Elapsed += new ElapsedEventHandler(DoUpdatePlayer); this.timer.Enabled = IsPlaying; }
protected override void Cleanup(bool finalRelease) { if (timer != null) { timer.Elapsed -= new ElapsedEventHandler(DoUpdatePlayer); timer.Dispose(); timer = null; } if (librarian != null) { librarian.Dispose(); librarian = null; } if (engine != null) { engine.LyricsUpdated -= new TrackHandler(DoLyricsUpdated); engine.LyricsProgressReport -= new LyricEngineProgress(DoLyricsProgressReport); engine.Dispose(); engine = null; } if (track != null) { Release(track); } try { OnAboutToPromptUserToQuitEvent -= quitHandler; OnDatabaseChangedEvent -= databaseChangedHandler; OnPlayerPlayEvent -= playHandler; OnPlayerPlayingTrackChangedEvent -= trackChangedHandler; OnPlayerStopEvent -= stopHandler; OnSoundVolumeChangedEvent -= volumeHandler; } catch { // no-op // Might happen if Alt-F4 is used to close the AppWindow } quitHandler = null; databaseChangedHandler = null; playHandler = null; trackChangedHandler = null; stopHandler = null; volumeHandler = null; }
/// <summary> /// Factory method returning the singleton instance. /// </summary> /// <returns></returns> public static Librarian Create(Controller controller) { if (librarian == null) { librarian = new Librarian(controller); } return librarian; }
/// <summary> /// Initialize a new instance of this scanner. /// </summary> /// <param name="itunes"></param> public InitializingScanner(Controller controller, Librarian librarian) : base(Resx.I_ScanInitialize, controller, librarian.Catalog) { base.description = Resx.ScanInitialize; this.librarian = librarian; }