激活/停用或安排視頻

本主題介紹如何使用CMS API .

簡介

您可能希望讓視頻在一段時間後無法播放的原因有多種。例如:

  • 還在審核中
  • 這是尚未上映的電影預告片
  • 它是尚未開始或結束的營銷活動的一部分
  • 這是尚未發布的新聞故事的一部分

如果您還沒有將視頻嵌入代碼放在公共頁面或應用程序中,當然無法觀看,但是視頻可能會被意外發布,最明顯的是它的標籤或其他屬性符合智能發布的播放列表。

有兩種方法可以確保無法查看視頻雲視頻:

  • 停用它
  • 安排它在未來的某個時間播放

這兩個更改都可以通過 Studio 中的媒體模塊實現,但這裡我們將介紹如何使用CMS API .這兩個操作都是使用 視頻更新請求執行的。

驗證

要求CMS API需要包含您的訪問令牌的授權標頭。如需有關如何取得用戶端認證並使用它們來擷取存取權杖的詳細資訊,請參閱 Brightcove OAuth 概觀

您可以使用 Studio 管理頁面OAuth API創建客戶端憑據

您還可以直接使用 OAuth API 來檢索訪問令牌,或者如果您使用的是 PostmanInsomnia 應用程序或發出您的請求,請參閱我們的教程,了解如何設置它們以獲取訪問令牌:

更新視頻請求

要更新視頻,請發送PATCH請求

https://cms.api.brightcove.com/v1/accounts/account_id/videos/video_id

通常,請求正文只需要包含您要更新的那些字段,但您也可以包含其他字段以及當前值。我們將在接下來的部分中查看激活/停用和調度的請求主體。

激活/停用視頻

視頻通過設置其活動(可見)或非活動(不可見)state .默認情況下,視頻是ACTIVE一旦它們被攝取(除非在創建視頻或使用上傳模塊上傳時省略了必填字段)。

然後要停用視頻,您只需將以下請求正文與更新視頻請求一起發送:

{
  "state": "INACTIVE"
}

您可以通過檢查state API 響應中的字段

範例回應
{
  "id": "1698990613556232930",
  "account_id": "57838016001",
  "ad_keys": null,
  "clip_source_video_id": null,
  "complete": true,
  "created_at": "2021-05-06T06:48:31.963Z",
  "created_by": {
    "type": "unknown"
  },
  "cue_points": [
  ],
  "custom_fields": {
  },
  "delivery_type": "dynamic_origin",
  "description": "Updated at: 2021-05-07T22:37:46.492Z",
  "digital_master_id": null,
  "duration": 41259,
  "economics": "AD_SUPPORTED",
  "folder_id": null,
  "geo": null,
  "has_digital_master": true,
  "images": {
    "poster": {
      "src": "https://cf-images.us-east-1.prod.boltdns.net/v1/jit/57838016001/1494916a-e8a7-45ac-882f-6e0aa3489846/main/1280x720/20s629ms/match/image.jpg",
      "sources": [
        {
          "src": "https://cf-images.us-east-1.prod.boltdns.net/v1/jit/57838016001/1494916a-e8a7-45ac-882f-6e0aa3489846/main/1280x720/20s629ms/match/image.jpg",
          "height": 720,
          "width": 1280
        }
      ]
    },
    "thumbnail": {
      "src": "https://cf-images.us-east-1.prod.boltdns.net/v1/jit/57838016001/1494916a-e8a7-45ac-882f-6e0aa3489846/main/160x90/20s629ms/match/image.jpg",
      "sources": [
        {
          "src": "https://cf-images.us-east-1.prod.boltdns.net/v1/jit/57838016001/1494916a-e8a7-45ac-882f-6e0aa3489846/main/160x90/20s629ms/match/image.jpg",
          "height": 90,
          "width": 160
        }
      ]
    }
  },
  "link": null,
  "long_description": null,
  "name": "Great Horned Owl",
  "original_filename": "greathornedowl.mp4",
  "projection": null,
  "published_at": "2021-05-06T06:48:31.963Z",
  "reference_id": "greathornedowl.mp4_1620283704192",
  "schedule": null,
  "sharing": null,
  "state": "INACTIVE",
  "tags": [
    "bird",
    "air",
    "nature"
  ],
  "text_tracks": [
  ],
  "updated_at": "2021-05-16T22:54:09.168Z",
  "updated_by": {
    "type": "api_key",
    "email": "rcrooks@brightcove.com"
  },
  "offline_enabled": false,
  "playback_rights_id": "primary"
}

要再次激活視頻,只需發送另一個帶有請求正文的更新視頻請求:

{
  "state": "ACTIVE"
}

安排視頻

使視頻可播放或不可播放的第二種方法是使用schedule視頻更新請求中的對象。這schedule object has two properties:

  • starts_at視頻可播放時的 ISO-8601 日期時間(必需)
  • ends_at視頻無法播放時的 ISO-8601 日期時間(可選)

這是一個示例請求正文,它使視頻可以在 2021 年 5 月 16 日早上 6:00 (UTC) 播放,並使其在整整一年後再次無法播放:

{
  "schedule": {
		"starts_at": "2021-05-16T06:00:00.000Z",
		"ends_at": "2022-05-16T06:00:00.000Z"
	}
}
範例回應
{
  "id": "1698990613556232930",
  "account_id": "57838016001",
  "ad_keys": null,
  "clip_source_video_id": null,
  "complete": true,
  "created_at": "2021-05-06T06:48:31.963Z",
  "created_by": {
    "type": "unknown"
  },
  "cue_points": [
  ],
  "custom_fields": {
  },
  "delivery_type": "dynamic_origin",
  "description": "Updated at: 2021-05-07T22:37:46.492Z",
  "digital_master_id": null,
  "duration": 41259,
  "economics": "AD_SUPPORTED",
  "folder_id": null,
  "geo": null,
  "has_digital_master": true,
  "images": {
    "poster": {
      "src": "https://cf-images.us-east-1.prod.boltdns.net/v1/jit/57838016001/1494916a-e8a7-45ac-882f-6e0aa3489846/main/1280x720/20s629ms/match/image.jpg",
      "sources": [
        {
          "src": "https://cf-images.us-east-1.prod.boltdns.net/v1/jit/57838016001/1494916a-e8a7-45ac-882f-6e0aa3489846/main/1280x720/20s629ms/match/image.jpg",
          "height": 720,
          "width": 1280
        }
      ]
    },
    "thumbnail": {
      "src": "https://cf-images.us-east-1.prod.boltdns.net/v1/jit/57838016001/1494916a-e8a7-45ac-882f-6e0aa3489846/main/160x90/20s629ms/match/image.jpg",
      "sources": [
        {
          "src": "https://cf-images.us-east-1.prod.boltdns.net/v1/jit/57838016001/1494916a-e8a7-45ac-882f-6e0aa3489846/main/160x90/20s629ms/match/image.jpg",
          "height": 90,
          "width": 160
        }
      ]
    }
  },
  "link": null,
  "long_description": null,
  "name": "Great Horned Owl",
  "original_filename": "greathornedowl.mp4",
  "projection": null,
  "published_at": "2021-05-06T06:48:31.963Z",
  "reference_id": "greathornedowl.mp4_1620283704192",
  "schedule": {
    "ends_at": "2022-05-16T06:00:00.000Z",
    "starts_at": "2021-05-16T06:00:00.000Z"
  },
  "sharing": null,
  "state": "ACTIVE",
  "tags": [
    "bird",
    "air",
    "nature"
  ],
  "text_tracks": [
  ],
  "updated_at": "2021-05-17T00:42:45.172Z",
  "updated_by": {
    "type": "api_key",
    "email": "rcrooks@brightcove.com"
  },
  "offline_enabled": false,
  "playback_rights_id": "primary"
}