Пример #1
0
        /// <summary>
        /// Adds a Captioning to an existing video
        /// http://docs.brightcove.com/en/media/reference.html#Video_Write
        /// The captions can either be uploaded to BC or be referred to by an external url
        /// BrightCove supports the DFXP and SMPTE-TT formats
        /// http://support.brightcove.com/en/docs/using-captions-smart-player-api
        /// </summary>
        /// <param name="caption_source">Metadata about the captions</param>
        /// <param name="options">Parameters (options) including the ID of the video that MUST be set</param>
        /// <param name="captions">a buffer containing DFXP or SMPTE-TT caption data</param>
        /// <returns>the captionSources object</returns>
        public RPCResponse <BCCaptionSources> AddCaptioning(BCCaptionSource caption_source, BCAddCaptioningOptions options, byte[] captions)
        {
            Dictionary <string, object> postParams = new Dictionary <string, object>();

            Builder builder = new Builder()
                              .AppendObject("caption_source", caption_source.ToJSON(JSONType.Create))
                              .Append(",").AppendField("token", Account.WriteToken.Value);

            if (!string.IsNullOrEmpty(options.filename))
            {
                builder.Append(",").AppendField("filename", options.filename);
            }

            if (options.maxsize > 0)
            {
                builder.Append(",").AppendField("maxsize", options.maxsize);
            }

            if (!string.IsNullOrEmpty(options.file))
            {
                throw new System.ArgumentException("The file property not supported.  Pass the captions in as a byte array.");
            }

            if (!string.IsNullOrEmpty(options.file_checksum))
            {
                builder.Append(",").AppendField("file_checksum", options.file_checksum);
            }

            // Either a video_id or video_reference_id is required
            if (options.video_id > 0)
            {
                builder.Append(",").AppendField("video_id", options.video_id);
            }
            else if (!string.IsNullOrEmpty(options.video_reference_id))
            {
                builder.Append(",").AppendField("video_reference_id", options.video_reference_id);
            }
            else
            {
                throw new System.ArgumentException("A video_id or video_reference_id is required for add_captioning");
            }

            RPCRequest rpc = new RPCRequest();

            rpc.method     = "add_captioning";
            rpc.parameters = builder.ToString();
            postParams.Add("json", rpc.ToJSON());

            postParams.Add("file", new UploadBufferParameter(captions, "captions.dfxp"));

            // Get the JSon reader returned from the APIRequest
            // RPCResponse<BCCaptionSources> rpcr = BCAPIRequest.ExecuteWriteFile<BCCaptionSources>(postParams, this.Account, @"C:\dev\svn\BrightCove\TestFormApp\sample_captions.dfxp");
            RPCResponse <BCCaptionSources> rpcr = BCAPIRequest.ExecuteWriteNew <BCCaptionSources>(postParams, this.Account);

            return(rpcr);
        }
Пример #2
0
      /// <summary>
      /// Adds a Captioning to an existing video
      /// http://docs.brightcove.com/en/media/reference.html#Video_Write
      /// The captions can either be uploaded to BC or be referred to by an external url
      /// BrightCove supports the DFXP and SMPTE-TT formats
      /// http://support.brightcove.com/en/docs/using-captions-smart-player-api
      /// </summary>
      /// <param name="caption_source">Metadata about the captions</param>
      /// <param name="options">Parameters (options) including the ID of the video that MUST be set</param>
      /// <param name="captions">a buffer containing DFXP or SMPTE-TT caption data</param>
      /// <returns>the captionSources object</returns>
      public RPCResponse<BCCaptionSources> AddCaptioning(BCCaptionSource caption_source, BCAddCaptioningOptions options, byte[] captions)
      {
			Dictionary<string, object> postParams = new Dictionary<string, object>();

         Builder builder = new Builder()
            .AppendObject("caption_source", caption_source.ToJSON(JSONType.Create))
            .Append(",").AppendField("token", Account.WriteToken.Value);

         if (!string.IsNullOrEmpty(options.filename))
            builder.Append(",").AppendField("filename", options.filename);

         if (options.maxsize > 0)
            builder.Append(",").AppendField("maxsize", options.maxsize);

         if (!string.IsNullOrEmpty(options.file))
            throw new System.ArgumentException("The file property not supported.  Pass the captions in as a byte array.");

         if (!string.IsNullOrEmpty(options.file_checksum))
            builder.Append(",").AppendField("file_checksum", options.file_checksum);

         // Either a video_id or video_reference_id is required
         if (options.video_id > 0)
            builder.Append(",").AppendField("video_id", options.video_id);
         else if (!string.IsNullOrEmpty(options.video_reference_id))
            builder.Append(",").AppendField("video_reference_id", options.video_reference_id);
         else
            throw new System.ArgumentException("A video_id or video_reference_id is required for add_captioning");

			RPCRequest rpc = new RPCRequest();
			rpc.method = "add_captioning";
         rpc.parameters = builder.ToString();
			postParams.Add("json", rpc.ToJSON());

         postParams.Add("file", new UploadBufferParameter(captions, "captions.dfxp"));

			// Get the JSon reader returned from the APIRequest
			// RPCResponse<BCCaptionSources> rpcr = BCAPIRequest.ExecuteWriteFile<BCCaptionSources>(postParams, this.Account, @"C:\dev\svn\BrightCove\TestFormApp\sample_captions.dfxp");
			RPCResponse<BCCaptionSources> rpcr = BCAPIRequest.ExecuteWriteNew<BCCaptionSources>(postParams, this.Account);

         return rpcr;
      }