public ml(string[] iArgs) { //Debugger.Launch(); args = iArgs; InitializeComponent(); // taskbar buttons ThumbnailToolBarButton buttonFirst = new ThumbnailToolBarButton(Properties.Resources.last1, "Last"); buttonFirst.Click += new EventHandler <ThumbnailButtonClickedEventArgs>(playPause); buttonFirst.Visible = buttonFirst.Enabled = true; ThumbnailToolBarButton buttonMiddle = new ThumbnailToolBarButton(Properties.Resources.playPause1, "Play"); buttonMiddle.Click += new EventHandler <ThumbnailButtonClickedEventArgs>(playPause); buttonMiddle.Visible = buttonMiddle.Enabled = true; ThumbnailToolBarButton buttonLast = new ThumbnailToolBarButton(Properties.Resources.next1, "Next"); buttonLast.Click += new EventHandler <ThumbnailButtonClickedEventArgs>(playPause); buttonLast.Visible = buttonLast.Enabled = true; TaskbarManager.Instance.ThumbnailToolBars.AddButtons(Handle, buttonFirst, buttonMiddle, buttonLast); PlayerManager.mediaPlayer = mediaPlayer = new MediaPlayer(logger, notifyIcon); mediaPlayer.linkVolume(prgVolume); mediaPlayer.linkPlayPauseButton(btnPlayPause); mediaPlayer.linkTrackbar(prgTimeDone); mediaPlayer.linkTimeLabels(lblTimeDone, lblTimeUp); mediaPlayer.linkUpNowLabels(lblUpNowTitle, lblUpNowArtist); mediaPlayer.linkCover(imgCover); hotkeyManager = new HotkeyManager(mediaPlayer, this.prgVolume); tbControl.SelectTab(1); server = new HttpWebServer(mediaPlayer, logger, prgVolume, args, forceServer: true); spotify = new Search.Spotify(listView1, spotifyContextMenu, notifyIcon, mediaPlayer); spotify.authorizeUser(); PlayerManager.logger = PlaylistManager.logger = logger; PlaylistManager.AutoPlaylists.updateSpecialPlaylists(); GameChecker gameChecker = new GameChecker(); GameLibraryManager.Initialise(gameChecker, server); Task.Factory.StartNew(() => updateUpdater()); }
private async Task initEndpoints(Logger logger) { Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("contentType", "images/jpeg"); Dictionary <string, string> jsonHeaders = new Dictionary <string, string>(); jsonHeaders.Add("contentType", "application/json"); server.GET("/favicon.ico") .Subscribe(ctx => ctx.Respond(getStream("ressources/faviconApollo.png"))); /* Pages */ server.GET("/") .Subscribe(ctx => ctx.Respond(File.ReadAllText("ressources/landingPage.html"))); server.GET("/control") .Subscribe(ctx => ctx.Respond(File.ReadAllText("ressources/coverSwipe.html"))); server.GET("/playlists") .Subscribe(ctx => ctx.Respond(File.ReadAllText("ressources/playlistStack.html"))); server.GET("/cover") .Subscribe(ctx => ctx.Respond(getStream(PlayerManager.cover), statusCode: 200, headers: headers)); server.GET("/radio") .Subscribe(ctx => ctx.Respond(File.ReadAllText("ressources/radio.html"))); server.GET("/games") .Subscribe(ctx => ctx.Respond(File.ReadAllText("ressources/games.html"))); server.GET("/games/validate-user/{user}") .Subscribe(ctx => { string user = ctx.Request.UriArguments.user; if (user == "null" || !users.ContainsKey(user)) { user = RandomString(6); users.Add(user, false); } ctx.Respond(user); }); /* now playing data */ server.GET("/version") .Subscribe(ctx => ctx.Respond("reAudioPlayer Apollo")); server.GET("/accent") .Subscribe(ctx => ctx.Respond(ColorTranslator.ToHtml(mediaPlayer.accentColour))); server.GET("/displayname") .Subscribe(ctx => ctx.Respond(PlayerManager.displayName)); // TODO server.GET("/get/volume") .Subscribe(ctx => { ctx.Respond(prgVolume.Value.ToString()); }); /* controls */ server.GET("/control/playPause") .Subscribe(ctx => { PlayerManager.playPause(); if (PlayerManager.isPlaying) { ctx.Respond(getStream("ressources/controls/webPlay.png")); } else { ctx.Respond(getStream("ressources/controls/webPause.png")); } }); server.GET("/control/next") .Subscribe(ctx => { PlayerManager.next(); ctx.Respond("OK"); }); server.GET("/control/last") .Subscribe(ctx => { PlayerManager.last(); ctx.Respond("OK"); }); server.GET("/control/load/playlist/{index}") .Subscribe(ctx => { var playlists = File.ReadAllLines(logger.playlistLib); int index = Convert.ToInt32(ctx.Request.UriArguments.index); mediaPlayer.loadPlaylist(playlists[index]); ctx.Respond("OK"); }); server.GET("/control/load/{index}") .Subscribe(ctx => { mediaPlayer.loadSong(Convert.ToInt32(ctx.Request.UriArguments.index)); ctx.Respond("OK"); }); server.GET("/control/volume/{value}") .Subscribe(ctx => { prgVolume.Invoke(new Action(() => { prgVolume.Value = Convert.ToInt32(ctx.Request.UriArguments.value); })); ctx.Respond("OK"); }); server.GET("/games/launch/{igdbId}&{user}") .Subscribe(ctx => { bool success = GameLibraryManager.launchGameByIGDBId(Convert.ToInt32(ctx.Request.UriArguments.igdbId), ctx.Request.UriArguments.user); if (success) { ctx.Respond("OK"); } else { ctx.Respond("You have been temporarily blocked!", 401); } }); /* playlist data */ server.GET("/data/playlists") // deprecated .Subscribe(ctx => { Debug.WriteLine("data/playlists called but deprecated"); var playlists = PlaylistManager.getPlaylistNamesAsStrings(); ctx.Respond(JsonConvert.SerializeObject(playlists)); }); server.GET("/data/games") .Subscribe(ctx => { ctx.Respond(GameLibraryManager.getInstalledGamesAsJSON()); }); server.GET("data/radio") .Subscribe(ctx => { var programmes = PlayerManager.getRadioProgrammes(); ctx.Respond(programmes); }); server.GET("v2/data/playlists") .Subscribe(ctx => { ctx.Respond(JsonConvert.SerializeObject(PlaylistManager.getDetailedPlaylists())); }); server.GET("data/playlist") .Subscribe(ctx => { List <Dictionary <string, string> > playlist = new List <Dictionary <string, string> >(); Dictionary <string, string> temp = new Dictionary <string, string>(); var songs = mediaPlayer.playlist; if (songs is null) { ctx.Respond(statusCode: 404); return; } foreach (var song in songs) { temp = new Dictionary <string, string>(); temp.Add("Number", songs.IndexOf(song).ToString()); temp.Add("Title", song.title); temp.Add("Artist", song.artist); temp.Add("Album", song.album); temp.Add("Duration", "N/A"); playlist.Add(temp); } ctx.Respond(JsonConvert.SerializeObject(playlist)); }); }