using System; using System.IO; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; namespace SingalDemo.Controllers { public class HomeController : Controller { private readonly IHostingEnvironment _env; private readonly IHubContext _pageHubContext; public HomeController(IHostingEnvironment env, IHubContext pageHubContext) { this._env = env; this._pageHubContext = pageHubContext; } public IActionResult Index() { return View(); } public IActionResult Command(string command, string args, string player = "web") { try { if (player == "web") { this._pageHubContext.Clients.All.SendAsync("command", command, args); } else if (player == "omx") { if (command == "play") { var file = Path.Combine(this._env.WebRootPath, "upload", $"{args}.mp4"); OmxPlayer.Play(file); } else if (command == "pause") { OmxPlayer.Pause(); } else if (command == "stop") { OmxPlayer.Stop(); } else if (command == "si") { OmxPlayer.SI(); } else if (command == "sd") { OmxPlayer.SD(); } else if (command == "vi") { OmxPlayer.VI(); } else if (command == "vd") { OmxPlayer.VD(); } } } catch (Exception ex) { return Content(ex.Message); } return Content(""); } } }