Ejemplo n.º 1
0
        public LiveBroadcast GenerateBroadCast()
        {
            //broadcast snippet contains basic info about the broadcast and this is shown on youtube when launched
            LiveBroadcastSnippet broadCastSnippet = new LiveBroadcastSnippet();

            broadCastSnippet.Title       = "Test";
            broadCastSnippet.Description = "A test of the youtube data API";
            //TODO: Add a thumbnail icon
            broadCastSnippet.ScheduledStartTime = DateTime.Now;

            //Applies settings of made for kids and unlisted to snippet i.e broadcast settings
            LiveBroadcastStatus broadCastStatus = new LiveBroadcastStatus();

            broadCastStatus.SelfDeclaredMadeForKids = false;
            broadCastStatus.PrivacyStatus           = "unlisted";

            //enables the broadcast to view a different "special stream" in case of time delays etc good for debugging
            MonitorStreamInfo broadCastMonitorStream = new MonitorStreamInfo();

            broadCastMonitorStream.EnableMonitorStream = true;

            //contains info about the monitor stream
            LiveBroadcastContentDetails broadCastContentDetails = new LiveBroadcastContentDetails();

            broadCastContentDetails.MonitorStream = broadCastMonitorStream;

            LiveBroadcast broadCast = new LiveBroadcast();

            broadCast.Snippet        = broadCastSnippet;        //binds the info regarding stream
            broadCast.Status         = broadCastStatus;         //privacy settings & reg settings
            broadCast.ContentDetails = broadCastContentDetails; //binds monitor info

            //Allows to finalise the setting up and is ready to be transmitted
            LiveBroadcastsResource.InsertRequest liveBroadCastInsert = service.LiveBroadcasts.Insert(broadCast, "snippet,status,contentDetails");
            //Reads the returned var

            LiveBroadcast returnedBroadCast = liveBroadCastInsert.Execute();

            Console.WriteLine("\n================== Returned Broadcast ==================\n");
            Console.WriteLine("  - Id: " + returnedBroadCast.Id);
            Console.WriteLine("  - Title: " + returnedBroadCast.Snippet.Title);
            Console.WriteLine("  - Description: " + returnedBroadCast.Snippet.Description);
            Console.WriteLine("  - Published At: " + returnedBroadCast.Snippet.PublishedAt);
            Console.WriteLine(
                "  - Scheduled Start Time: " + returnedBroadCast.Snippet.ScheduledStartTime);
            Console.WriteLine(
                "  - Scheduled End Time: " + returnedBroadCast.Snippet.ScheduledEndTime);

            return(returnedBroadCast);
        }
Ejemplo n.º 2
0
        public YoutubeApi()
        {
            service = Auth();

            var broadcastSnippet = new LiveBroadcastSnippet();

            broadcastSnippet.Title = "Biometrico";
            broadcastSnippet.ScheduledStartTime = DateTime.Now;

            var broadcastStatus = new LiveBroadcastStatus();

            broadcastStatus.PrivacyStatus = "unlisted";

            var broadcastMonitorStream = new MonitorStreamInfo();

            broadcastMonitorStream.EnableMonitorStream = true;

            var broadcastContentDetails = new LiveBroadcastContentDetails();

            broadcastContentDetails.MonitorStream = broadcastMonitorStream;

            var broadcast = new LiveBroadcast();

            broadcast.Kind           = "youtube#liveBroadcast";
            broadcast.Snippet        = broadcastSnippet;
            broadcast.Status         = broadcastStatus;
            broadcast.ContentDetails = broadcastContentDetails;

            var liveBroadcastInsert = service.LiveBroadcasts.Insert(broadcast, "snippet,status,contentDetails");
            var returnedBroadcast   = liveBroadcastInsert.Execute();

            Console.WriteLine("\n================== Returned Broadcast ==================\n");
            Console.WriteLine("  - Id: " + returnedBroadcast.Id);
            Console.WriteLine("  - Title: " + returnedBroadcast.Snippet.Title);
            Console.WriteLine("  - Description: " + returnedBroadcast.Snippet.Description);
            Console.WriteLine("  - Published At: " + returnedBroadcast.Snippet.PublishedAt);
            Console.WriteLine(
                "  - Scheduled Start Time: " + returnedBroadcast.Snippet.ScheduledStartTime);
            Console.WriteLine(
                "  - Scheduled End Time: " + returnedBroadcast.Snippet.ScheduledEndTime);

            var streamSnippet = new LiveStreamSnippet();

            streamSnippet.Title = "Camara de Establecimiento";

            var cdnSettings = new CdnSettings();

            cdnSettings.Format        = "720p";
            cdnSettings.IngestionType = "rtmp";

            var stream = new LiveStream();

            stream.Kind    = "youtube#liveStream";
            stream.Snippet = streamSnippet;
            stream.Cdn     = cdnSettings;

            var liveStreamInsert = service.LiveStreams.Insert(stream, "snippet,cdn");
            var returnedStream   = liveStreamInsert.Execute();

            Console.WriteLine("\n================== Returned Stream ==================\n");
            Console.WriteLine("  - Id: " + returnedStream.Id);
            Console.WriteLine("  - Title: " + returnedStream.Snippet.Title);
            Console.WriteLine("  - Description: " + returnedStream.Snippet.Description);
            Console.WriteLine("  - Published At: " + returnedStream.Snippet.PublishedAt);
            Console.WriteLine("  - URL: " + returnedStream.Cdn.IngestionInfo.IngestionAddress);
            Console.WriteLine("  - Name: " + returnedStream.Cdn.IngestionInfo.StreamName);

            var liveBroadcastBind = service.LiveBroadcasts.Bind(returnedBroadcast.Id, "id, contentDetails");

            liveBroadcastBind.StreamId = returnedStream.Id;
            returnedBroadcast          = liveBroadcastBind.Execute();

            Console.WriteLine("\n================== Returned Bound Broadcast ==================\n");
            Console.WriteLine("  - Broadcast Id: " + returnedBroadcast.Id);
            Console.WriteLine("  - Bound Stream Id: " + returnedBroadcast.ContentDetails.BoundStreamId);

            var liveStreamRequest = service.LiveStreams.List("id,status");

            liveStreamRequest.Id = returnedStream.Id;

            string streamLoop = "0";

            while (!streamLoop.Contains("A"))
            {
                var returnedStreamListResponse = liveStreamRequest.Execute();
                var foundStream = returnedStreamListResponse.Items.Single();
                Console.WriteLine(foundStream.Status.StreamStatus);
                streamLoop = Console.ReadKey().Key.ToString();
            }


            returnedBroadcast.ContentDetails.MonitorStream.EnableMonitorStream = false;
            service.LiveBroadcasts.Update(returnedBroadcast, "contentDetails");
            var liveBroadcastRequest = service.LiveBroadcasts.List("id,status,contentDetails");

            liveBroadcastRequest.Id = returnedBroadcast.Id;

            char broadcastLoop = '0';

            while (broadcastLoop != ('A'))
            {
                var returnedBroadcastListResponse = liveBroadcastRequest.Execute();
                var foundBroadcast = returnedBroadcastListResponse.Items.Single();
                Console.WriteLine(foundBroadcast.ContentDetails.MonitorStream.EnableMonitorStream);
                broadcastLoop = Console.ReadKey().KeyChar;
            }

            service.LiveBroadcasts.Transition(LiveBroadcastsResource.TransitionRequest.BroadcastStatusEnum.Testing, returnedBroadcast.Id, "");

            broadcastLoop = '0';
            while (broadcastLoop != 'A')
            {
                var returnedBroadcastListResponse = liveBroadcastRequest.Execute();
                var foundBroadcast = returnedBroadcastListResponse.Items.Single();
                Console.WriteLine(foundBroadcast.Status.LifeCycleStatus);
                broadcastLoop = Console.ReadKey().KeyChar;
            }

            service.LiveBroadcasts.Transition(LiveBroadcastsResource.TransitionRequest.BroadcastStatusEnum.Live, returnedBroadcast.Id, "");

            broadcastLoop = '0';
            while (broadcastLoop != ('A'))
            {
                var returnedBroadcastListResponse = liveBroadcastRequest.Execute();
                var foundBroadcast = returnedBroadcastListResponse.Items.Single();
                Console.WriteLine(foundBroadcast.Status.LifeCycleStatus);
                broadcastLoop = Console.ReadKey().KeyChar;
            }


            //rtsp://192.168.1.99/axis-media/media.amp
        }