public IActionResult LiveEvents() { List <MediaLiveEvent> mediaLiveEvents = new List <MediaLiveEvent>(); string authToken = HomeController.GetAuthToken(Request, Response); using (MediaClient mediaClient = new MediaClient(authToken)) { LiveEvent[] liveEvents = mediaClient.GetAllEntities <LiveEvent>(MediaEntity.LiveEvent); foreach (LiveEvent liveEvent in liveEvents) { MediaLiveEvent mediaLiveEvent = new MediaLiveEvent(mediaClient, liveEvent); mediaLiveEvents.Add(mediaLiveEvent); } ViewData["streamingPolicies"] = JobController.GetStreamingPolicies(mediaClient); } ViewData["liveEvents"] = mediaLiveEvents.ToArray(); return(View()); }
public IActionResult LiveEvents() { List <MediaLiveEvent> mediaLiveEvents = new List <MediaLiveEvent>(); string authToken = HomeController.GetAuthToken(Request, Response); using (MediaClient mediaClient = new MediaClient(authToken)) { LiveEvent[] liveEvents = mediaClient.GetAllEntities <LiveEvent>(MediaEntity.LiveEvent); foreach (LiveEvent liveEvent in liveEvents) { MediaLiveEvent mediaLiveEvent = new MediaLiveEvent(mediaClient, liveEvent); mediaLiveEvents.Add(mediaLiveEvent); } ViewData["streamingPolicies"] = JobController.GetStreamingPolicies(mediaClient); } ViewData["liveEvents"] = mediaLiveEvents.ToArray(); ViewData["inputStreamId"] = AuthToken.GetClaimValue(authToken, Constant.UserAttribute.MediaAccountSubscriptionId); return(View()); }
public JsonResult StartEvent(string eventName) { try { string authToken = HomeController.GetAuthToken(Request, Response); using (MediaClient mediaClient = new MediaClient(authToken)) { LiveEvent liveEvent = mediaClient.GetEntity <LiveEvent>(MediaEntity.LiveEvent, eventName); MediaLiveEvent mediaLiveEvent = new MediaLiveEvent(mediaClient, liveEvent); if (mediaLiveEvent.Outputs.Length == 0) { string eventOutputName = string.Concat(eventName, Constant.Media.LiveEvent.Output.NameSuffix); string eventOutputAssetName = Guid.NewGuid().ToString(); string streamingPolicyName = PredefinedStreamingPolicy.ClearStreamingOnly; int archiveWindowMinutes = Constant.Media.LiveEvent.Output.DefaultArchiveMinutes; CreateOutput(eventName, eventOutputName, null, eventOutputAssetName, streamingPolicyName, archiveWindowMinutes); } mediaClient.StartLiveEvent(eventName); } return(Json(eventName)); } catch (ValidationException ex) { Error error = new Error() { Type = HttpStatusCode.BadRequest, Message = ex.Message }; return(new JsonResult(error) { StatusCode = (int)error.Type }); } catch (ApiErrorException ex) { return(new JsonResult(ex.Response.Content) { StatusCode = (int)ex.Response.StatusCode }); } }
public JsonResult StopEvent(string eventName) { try { string authToken = HomeController.GetAuthToken(Request, Response); using (MediaClient mediaClient = new MediaClient(authToken)) { mediaClient.StopLiveEvent(eventName); LiveEvent liveEvent = mediaClient.GetEntity <LiveEvent>(MediaEntity.LiveEvent, eventName); MediaLiveEvent mediaLiveEvent = new MediaLiveEvent(mediaClient, liveEvent); foreach (LiveOutput liveOutput in mediaLiveEvent.Outputs) { mediaClient.DeleteEntity(MediaEntity.LiveEventOutput, liveOutput.Name, mediaLiveEvent.Name); } } return(Json(eventName)); } catch (ValidationException ex) { Error error = new Error() { Type = HttpStatusCode.BadRequest, Message = ex.Message }; return(new JsonResult(error) { StatusCode = (int)error.Type }); } catch (ApiErrorException ex) { return(new JsonResult(ex.Response.Content) { StatusCode = (int)ex.Response.StatusCode }); } }