Пример #1
0
        public ActionResult LiveBroadcast()
        {
            LiveStream ls = new Models.LiveStream();
            var context = AzureVidMan.Utils.VidProcessUtil.GetMediaContext();
            var channel = context.Channels.Where(x => x.Name == "VidMan").FirstOrDefault();
            if (channel != null)
            {
                if (channel.Input != null)
                    ls.InjestURL = channel.Input.Endpoints.FirstOrDefault().Url.ToString();

                if (channel.Preview != null)
                    ls.PreviewURL = channel.Preview.Endpoints.FirstOrDefault().Url.ToString();

                ls.ThumbnailURL = new UriBuilder
                {
                    Scheme = Uri.UriSchemeHttps,
                    Host = channel.Preview.Endpoints.FirstOrDefault().Url.Host,
                    Path = "thumbnails/input.jpg"
                }.Uri.ToString();

                if (channel.State == ChannelState.Starting)
                {
                    ls.Status = "Channel Starting";
                }
                else if (channel.State == ChannelState.Stopping)
                {
                    ls.Status = "Channel Stopping";
                }
                else if (channel.State == ChannelState.Deleting)
                {
                    ls.Status = "Channel Deleting";
                }
                else
                {
                    if (channel.Programs.Count() > 0)
                    {
                        var program = channel.Programs.FirstOrDefault();
                        ls.Status = program.State.ToString();

                        IAsset asset = context.Assets.Where(x => x.Name == "VidManLiveAsset").FirstOrDefault();
                        var locator = asset.Locators.FirstOrDefault();
                        var ismFile = (from f in asset.AssetFiles where f.Name.EndsWith(".ism") select f).FirstOrDefault();
                        if (locator != null && ismFile != null)
                        {
                            string broadcastURL = locator.Path + ismFile.Name + "/manifest";
                            ls.BroadcastURL = broadcastURL;
                        }
                    }
                    else
                        ls.Status = "No program available";
                }
            }
            else
                ls.Status = "No channel configured";

            return View(ls);
        }
Пример #2
0
        // GET: Admin/LiveStream
        public ActionResult LiveStream()
        {
            LiveStream ls = new Models.LiveStream();
            var context = AzureVidMan.Utils.VidProcessUtil.GetMediaContext();
            var channel = context.Channels.Where(x => x.Name == "VidMan").FirstOrDefault();
            if (channel != null)
            {
                ls.InjestURL = channel.Input.Endpoints.FirstOrDefault().Url.ToString();
                ls.PreviewURL= channel.Preview.Endpoints.FirstOrDefault().Url.ToString();
                ls.ThumbnailURL= new UriBuilder
                    {
                        Scheme = Uri.UriSchemeHttps,
                        Host = channel.Preview.Endpoints.FirstOrDefault().Url.Host,
                        Path = "thumbnails/input.jpg"
                    }.Uri.ToString();
                ls.Status = channel.State.ToString();
            }

            return View(ls);
        }
Пример #3
0
        public async Task<JsonResult> StartLiveStream()
        {
            LiveStream ls = new Models.LiveStream();
            var context = AzureVidMan.Utils.VidProcessUtil.GetMediaContext();

            //Channel is stopped and needs to run
            IChannel newChannel = await Utils.LiveStreamUtils.CreateAndStartChannel(context, "VidMan");

            //Refresh channel object
            newChannel = context.Channels.Where(x => x.Name == "VidMan").FirstOrDefault();

            //Ensure channel is fully up and running before we continue
            while (newChannel.State!= ChannelState.Running)
            {
                await Task.Delay(5000);
                newChannel = context.Channels.Where(x => x.Name == "VidMan").FirstOrDefault();
            }

            ls.InjestURL = newChannel.Input.Endpoints.FirstOrDefault().Url.ToString();
            ls.PreviewURL = newChannel.Preview.Endpoints.FirstOrDefault().Url.ToString();

            ls.ThumbnailURL = new UriBuilder
            {
                Scheme = Uri.UriSchemeHttps,
                Host = newChannel.Preview.Endpoints.FirstOrDefault().Url.Host,
                Path = "thumbnails/input.jpg"
            }.Uri.ToString();

            IProgram program = Utils.LiveStreamUtils.CreateAndStartProgram(context, newChannel);
            ILocator locatior = Utils.LiveStreamUtils.CreateLocatorForAsset(context, program.Asset, program.ArchiveWindowLength);
            IStreamingEndpoint streamingEndpoint;

            if (context.StreamingEndpoints.Count() > 0)
                streamingEndpoint = context.StreamingEndpoints.FirstOrDefault();
            else
                streamingEndpoint = Utils.LiveStreamUtils.CreateAndStartStreamingEndpoint(context);

            Utils.LiveStreamUtils.GetLocatorsInAllStreamingEndpoints(context, program.Asset);

            ls.Status = program.State.ToString();

            Utils.LiveVideoStatus.IsLive = false;

            return Json(new {Status=ls.Status, InjestURL = ls.InjestURL,PreviewURL = ls.PreviewURL,ThumbnailURL = ls.ThumbnailURL});
        }
Пример #4
0
        public async Task<JsonResult> StopLiveStream()
        {
            LiveStream ls = new Models.LiveStream();
            var context = AzureVidMan.Utils.VidProcessUtil.GetMediaContext();
            var channel = context.Channels.Where(x => x.Name == "VidMan").FirstOrDefault();
            if (channel != null)
            {
                //Channel is running and needs to stop
                Utils.LiveStreamUtils.Cleanup(context, channel);
                ls.Status = "Stopped";
                ls.InjestURL = string.Empty;
                ls.PreviewURL = string.Empty;
                ls.ThumbnailURL = string.Empty;
            }

            Utils.LiveVideoStatus.IsLive = false;

            return Json(new { Status = ls.Status, InjestURL = ls.InjestURL, PreviewURL = ls.PreviewURL, ThumbnailURL = ls.ThumbnailURL });
        }