/// <summary> /// Turn the screen on or off as requested. Also optionally turn on/off JRMC music visualization /// </summary> /// <param name="mode">0: Off; 1: On/Normal; 2: On/Visualize (JRMC only)</param> public static void SetScreenDisplayMode( int mode) { logger.Info("SetScreenDisplayMode {0}", mode); if (mode == 0) { TurnOff(); if (Running.RunningProgram == "Music") { JRMC.SetDisplay(JRMC.DisplayMode.Mini); } } else { if (!Receiver.IsOn()) { Receiver.SelectTVOutput(); } TurnOn(); if (Running.RunningProgram == "Music") { JRMC.SetDisplay(mode == 2 ? JRMC.DisplayMode.Display : JRMC.DisplayMode.Standard); } } currentMode = mode; }
// GET: /Action/RebuildMediaDb public ActionResult RebuildMediaDb() { if (Running.RunningProgram != "Video" && Running.RunningProgram != "Spotify") { JRMC.LoadAndIndexAllAlbums(new string[] { "1", "2" }, true); } DvbViewer.CleanupRefreshDB(); Spotify.LoadAndIndexAllSavedTracks(); return(Content("")); }
// GET: /Music/GetPlayingInfo public ContentResult GetPlayingInfo() { StringWriter writer = new StringWriter(); var info = JRMC.GetPlaybackInfo(); if (info != null) { info.Save(writer); } return(this.Content(writer.ToString(), @"text/xml", writer.Encoding)); }
// GET: /Music/PlayListenAgain public ContentResult PlayListenAgain( string pid) { string name; string station; DateTime startTime; string streamUrl = BBC.GetStreamUrl(pid, out name, out station, out startTime); JRMC.SetStreaming(name, station, startTime); JRMC.GetXml(JRMC.Url + "Control/CommandLine?Arguments=/Play " + HttpUtility.UrlEncode(streamUrl)); return(this.Content("")); }
// GET: /Music/SendMCWS public ContentResult SendMCWS( string url) { if (url.StartsWith("Playback/PlayByKey?")) { JRMC.ClearStreaming(); } // Can't seek streamed radio if (url.StartsWith("Playback/Position?") && JRMC.IsStreaming()) { return(this.Content("")); } XDocument doc = JRMC.GetXml(JRMC.Url + url); return(this.Content(doc.ToString(), @"text/xml")); }
/// <summary> /// Launch the player applictaion (which will only be the Photo viewer) leaving any JRMC music still playing /// </summary> /// <param name="name"></param> /// <param name="args"></param> /// <returns></returns> public static bool LaunchNewProgram( string name, string args) { logger.Info("LaunchNewProgram {0} -> {1}", runningProgram, name); lastActive = DateTime.UtcNow; runningArgs = ""; if (name == "Photo") { if (runningProgram == "Photo") { ExitJRMC(); Thread.Sleep(500); } Zoom.Stop(); DvbViewer.Stop(); if (spotifyRunning) { Spotify.Stop(); } DesktopClient.ExitAllPrograms(); Receiver.SelectComputerInput(); Receiver.ReselectInput(); Screen.EnsureScreenOn(); Receiver.SelectRoomsOutput(); Screen.WaitForScreenOn(); runningProgram = "Photo"; if (DesktopClient.LaunchNewProgram(name, args)) { JRMC.SetDisplay(JRMC.DisplayMode.Display, maximize: true); logger.Info("LaunchProgram OK {0}", runningProgram); return(true); } } return(false); }
/// <summary> /// Return as XML, information about the curently playing track /// </summary> /// <returns></returns> public static XElement GetPlaybackInfo() { var x = GetXml(Url + "Playback/Info"); if (x != null) { var trackId = x.Root.DescendantsAndSelf("Item").Where(el => el.Attribute("Name").Value == "FileKey").First().Value; var track = JRMC.GetTrackByTrackId(trackId); if (track != null) { var composerDisplay = ""; // Add an additional "ClassicalComposer" if that does not duplicate information in the track name if (track.Info.ContainsKey("Composer") && track.Info.ContainsKey("Genre")) { var genre = track.Info["Genre"]; var composerName = track.Info["Composer"]; var name = track.Info["Name"]; if (genre == "Classical" && composerName != "" && !name.StartsWith(composerName, StringComparison.InvariantCultureIgnoreCase)) { composerDisplay = composerName + ": "; } } x.Root.Add(new XElement("Item", new XAttribute("Name", "ClassicalComposer"), composerDisplay)); } // Fake up some data when plating a streamed URL if (currentStreamingName != null) { SetItemValueInInfo(x.Root, "Name", currentStreamingName); SetItemValueInInfo(x.Root, "Artist", currentStreamingStation); SetItemValueInInfo(x.Root, "Album", currentStreamingStartTime.ToString("ddd HH:mm")); SetItemValueInInfo(x.Root, "ImageURL", "/Music/GetListenAgainIcon"); } return(x.Root); } return(null); }
protected void Application_Start() { logger.Info("Avid 4 Started"); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); JRMC.LoadAndIndexAllAlbums(new string[] { "1", "2" }, DateTime.Now.Hour < 5); // Reload album data from JRMC when restarting between midnight and five (i.e. in the overnight restart) DesktopClient.Initialize(); Receiver.Initialize(); Running.Initialize(); Spotify.Initialize(); DvbViewer.Initialize(); Security.Initialize(); #if USE_SKY_STB SkyData.Initialize(Config.SkyFavourites, Config.SkyRadio, Config.SkyPackages, Config.SkyCapacityGB); var sky = SkyData.Sky; #endif }
/// <summary> /// Is the currently running player showing signs of activity? /// </summary> /// <returns></returns> static Boolean IsActive() { // If a music player is stopped or paused, it may have been forgotten switch (runningProgram) { default: // If the screen is off and the volume is muted, it may have been forgotten // So treat as inactive return(Screen.IsOn || !Receiver.VolumeMuted); case "Music": return(JRMC.IsActivelyPlaying()); case "Spotify": return(Spotify.GetPlaying() > 0); case "Video": return(Zoom.IsCurrentlyActive); case "TV": case "Radio": return(DvbViewer.CurrentlySelectedChannel != null); } }
/// <summary> /// Main initialization and re-initialization method to load and index all albums from the JRMC web API into /// the optimized and indexed storate /// </summary> /// <param name="itemIds"></param> /// <param name="refresh"></param> /// <returns></returns> public static AlbumCollection LoadAndIndexAllAlbums( string[] itemIds, bool refresh) { // THe information is normally loaded from a cache in a fixed location const string CachePath = @"C:\Avid.Net\Avid4.Net\JRMC Cache.bin"; // IF we are explicitly refreshing the cache, delete the old one if (refresh && File.Exists(CachePath)) { File.Delete(CachePath); } // If we have a cache (which we normally will), use it by simple binary deserialization if (File.Exists(CachePath)) { IFormatter formatter = new BinaryFormatter(); using (FileStream s = File.OpenRead(CachePath)) { theJRMC = (JRMC)formatter.Deserialize(s); } } else { // We are loading all data from JRMC if (theJRMC == null) { theJRMC = new JRMC(); } try { // Create and fetch all music and photo albums theJRMC.albumList = new AlbumCollection(); theJRMC.photoAlbumList = new AlbumCollection(); foreach (var itemId in itemIds) { FetchAllAlbums(itemId, AlbumList, PhotoAlbumList); } } catch { theJRMC.albumList = null; } // If we have created an album list, save it to the cache for next time if (AlbumList != null) { IFormatter formatter = new BinaryFormatter(); using (FileStream s = File.Create(CachePath)) { formatter.Serialize(s, theJRMC); } } } // Irrespective f how we loaded the album and track information, build all internal index if (AlbumList != null) { BuildIndexesByTrackId(); BuildIndexByComposer(); BuildIndexByArtist(); } foreach (var a in GetVeryRecentlyPlayed()) { logger.Info("Recently Played: {0} ({1}) {2}", a.GetAlbumName(), a.GetArtistName(), a.GetAlbumDateLastPlayed().ToString()); } return(AlbumList); }
/// <summary> /// Command the JRMC player to stop and and hide itself /// </summary> private static void ExitJRMC() { JRMC.ExitDisplay(runningProgram == "Photo"); }
/// <summary> /// Launch a specified player application, closing any others as appropriate, and configuring /// the screen and receiver to suit the preferred outputs fr that player /// </summary> /// <param name="name"></param> /// <param name="args"></param> /// <returns></returns> public static bool LaunchProgram( string name, string args) { logger.Info("LaunchProgram {0} -> {1} {2}", runningProgram, name, args ?? ""); lastActive = DateTime.UtcNow; runningArgs = args; if (name != "Sky") { StopSky(); } if (name != "Roku") { StopRoku(); } Receiver.SelectComputerInput(); if (name == "Music") { if (runningProgram != name) { if (runningProgram == "Photo") { ExitJRMC(); } Zoom.Stop(); DvbViewer.Stop(); if (spotifyRunning) { Spotify.Stop(); } DesktopClient.ExitAllPrograms(); runningProgram = name; Screen.SetScreenDisplayMode(0); Receiver.SelectRoomsOutput(); } JRMC.SetDisplay(JRMC.DisplayMode.Standard, maximize: true); logger.Info("LaunchProgram OK {0}", runningProgram); return(true); } if (runningProgram == name && String.IsNullOrEmpty(args)) { if (runningProgram != "Spotify" && !DesktopClient.ForegroundProgram(name)) { Zoom.Stop(); DvbViewer.Stop(); if (spotifyRunning) { Spotify.Stop(); } DesktopClient.ExitAllPrograms(); NothingRunning(); return(false); } logger.Info("LaunchProgram OK {0}", runningProgram); return(true); } if (runningProgram == "Music" || runningProgram == "Photo") { ExitJRMC(); } if (runningProgram == "TV") { DvbViewer.Stop(); } runningProgram = name; switch (name) { default: return(false); case "TV": if (args != null && args == "Radio") { Screen.SetScreenDisplayMode(0); Receiver.SelectRoomsOutput(); } else { Screen.EnsureScreenOn(); Receiver.SelectTVOutput(); Screen.WaitForScreenOn(); } if (!DesktopClient.LaunchProgram("TV", null)) { NothingRunning(); return(false); } logger.Info("LaunchProgram OK {0}", runningProgram); return(true); case "Web": Screen.EnsureScreenOn(); Receiver.SelectTVOutput(); Screen.WaitForScreenOn(); if (!DesktopClient.LaunchProgram("Web", args)) { NothingRunning(); return(false); } logger.Info("LaunchProgram OK {0}", runningProgram); return(true); case "Video": Screen.EnsureScreenOn(); Receiver.SelectTVOutput(); //Screen.WaitForScreenOn(); if (args == null) { return(true); } if (!DesktopClient.LaunchProgram("Video", args)) { NothingRunning(); return(false); } zoomRunning = true; logger.Info("Zoom.Start"); Zoom.Start(); logger.Info("LaunchProgram OK {0}", runningProgram); return(true); case "Spotify": Screen.SetScreenDisplayMode(0); Receiver.SelectRoomsOutput(); DesktopClient.ExitAllPrograms(); DesktopClient.EnsureSpotifyRunning(); spotifyRunning = true; logger.Info("LaunchProgram OK {0}", runningProgram); return(true); } }
// GET: /Music/RemoveQueuedTrack public ContentResult RemoveQueuedTrack( string id) { JRMC.RemoveQueuedTrack(id); return(this.Content("")); }