このトピックでは、API 操作を呼び出してプレイリストモードでプロダクションスタジオをライブストリーミングに使用する方法について説明します。プレイリストモードのプロダクションスタジオを使用すると、さまざまなコンテンツタイプやシナリオにわたって、ライブストリーミング用に複数の動画をすばやく集約できます。これにより、スケジュールされた時間にライブストリーミングを開始でき、より多様なコンテンツを提供し、ユーザーの安定性を向上させることができます。コマーシャルは、リアルタイムまたはスケジュールされた時間に自動的に挿入でき、収益の増加に役立ちます。
概要
次の手順に従って、プレイリストモードのプロダクションスタジオをライブストリーミングに使用できます。
ビデオオンデマンド (VOD) バケットの有効化: ApsaraVideo VOD を有効化すると、各リージョンに独立した VOD バケットが割り当てられます。リージョンでメディアリソースをアップロードおよび管理する前に、バケットを有効化する必要があります。追加の設定は不要です。
動画のアップロード: 再生する順序で VOD バケットに動画をアップロードします。
ストリーミングドメインの追加: ストリーミングドメインは、ライブストリームのストリーミング URL を提供します。視聴者はこの URL を使用してライブストリームを視聴できます。
API 操作を呼び出してプレイリストモードでプロダクションスタジオを設定する: API 操作を呼び出して、各動画の再生回数とエピソードリストの繰り返し回数を指定できます。たとえば、動画 A は 1 回、B は 2 回、C は 3 回再生されます。これらの手順を完了したら、エピソードリストの再生情報をクエリして再生を開始します。
前提条件
Alibaba Cloud アカウントが作成され、実名検証に合格していること。
ApsaraVideo VOD、ApsaraVideo Live、および Cloud Production Studio サービスが有効化されていること。詳細については、「ApsaraVideo VOD の有効化」、「ApsaraVideo Live の有効化とリソースプランの購入」、および「Cloud Production Studio サービスの有効化」をご参照ください。
説明プロダクションスタジオ機能は現在、中国 (上海)、中国 (北京)、シンガポール、およびインドネシア (ジャカルタ) リージョンでのみサポートされており、今後さらに多くのリージョンでサポートされる予定です。
ストリーミングドメインを準備していること。クイックスタートとして、ライブセンターを中国本土以外のリージョンに設定し、アクセラレーションリージョンを 中国本土以外 に設定することを推奨します。これにより、ストリーミングドメインの ICP (Internet Content Provider) 申請が不要になります。
AliyunFCFullAccess、AliyunLiveFullAccess、および AliyunVODFullAccess ポリシーが Resource Access Management (RAM) ユーザーにアタッチされていること。詳細については、「RAM ユーザーの作成と権限付与」をご参照ください。
ステップ 1: VOD バケットを有効化する
ApsaraVideo VOD コンソールで、[設定管理] > [メディア管理設定] > [ストレージ] を選択し、VOD システムバケットの [VOD バケットを有効にする] をクリックします。
バケットが有効化されるまで待ちます。システムに [バケットが正常に有効化されました] というメッセージが表示され、バケットのステータスが [通常] になってからのみ、バケットを使用できます。

ステップ 2: 動画をアップロードする
ApsaraVideo VOD コンソールの ページで、[アップロード] をクリックできます。
[メディアのアップロード] ページで、[メディアの追加] をクリックします。

[メディアの追加] ダイアログボックスで、[ローカルアップロード] を選択し、ローカルデバイスから準備した 3 つのビデオファイルを選択して、[アップロード] をクリックします。

アップロードが成功したら、[オーディオ/ビデオ] ページでリソース ID を表示して記録します。次に、[操作] 列で [その他] > [Cloud Studio で利用可能にする] をクリックして、コンテンツを ApsaraVideo Live のプロダクションスタジオでリアルタイムに表示できるようにします。プロダクションスタジオの機能については、「機能エリアの概要」をご参照ください。

ステップ 3: ストリーミングドメインを追加する
ApsaraVideo Live コンソールで、アップストリームミングまたはストリーミングのドメイン名管理 ページに移動し、ドメイン名の追加 をクリックします。
必要に応じてドメイン名を設定します。[次へ] をクリックします。パラメーターの詳細については、「高速化ドメイン名の追加」をご参照ください。

後で使用するために、生成された CNAME を記録します。

Alibaba Cloud DNS - パブリック権威解決 ページで、設定するドメイン名を見つけ、[操作] 列の [設定] をクリックします。
Add Record をクリックし、CNAME 設定を完了して、[確認] をクリックします。詳細については、「ドメイン名の CNAME 解決の設定」をご参照ください。

ステップ 4: API 操作を呼び出してプレイリストモードでプロダクションスタジオを設定する
Intellij IDEA を開き、Maven プロジェクトを作成します。pom.xml ファイルで、<dependencies></dependencies> タグを作成し、次の依存関係を追加します。
<dependency> <groupId>com.aliyun</groupId> <artifactId>live20161101</artifactId> <version>2.0.0</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.76</version> </dependency>src/main/javaディレクトリで、`java` を右クリックして Java クラスを作成します。この例では、Java クラスに bodan という名前を付けます。次のパラメーターを設定し、サンプルコードを実行します。
package com.alibaba.aliyundebug.common; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.aliyun.live20161101.Client; import com.aliyun.live20161101.models.*; import com.aliyun.teaopenapi.models.Config; import org.apache.commons.codec.digest.DigestUtils; import java.util.List; import java.util.Random; import java.util.UUID; public class Bodan { private final static String ACCESS_KEY_ID = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"); private final static String ACCESS_KEY_SECRET = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"); private static class LiveClient { private static volatile Client instance; private LiveClient() { } public static Client getInstance(String endpoint, String accessKeyId, String accessKeySecret) { if (instance == null) { synchronized (LiveClient.class) { if (instance == null) { try { Config config = new Config(); config.setEndpoint(endpoint); config.setAccessKeyId(accessKeyId); config.setAccessKeySecret(accessKeySecret); instance = new Client(config); } catch (Exception e) { throw new RuntimeException("Live client initialization failed: " + e.getMessage(), e); } } } } return instance; } } private static CreateCasterResponse createCaster(Client client) throws Exception { CreateCasterRequest request = new CreateCasterRequest(); Random random = new Random(); int i = random.nextInt(100000); request.setCasterName("casterName" + i); UUID uuid = UUID.randomUUID(); String token = "thisIsaToken"; String clientToken = DigestUtils.sha256Hex(token + uuid); request.setClientToken(clientToken); // エピソードリストを使用するには、プレイリストモードでプロダクションスタジオを作成するだけで済みます。 request.setNormType(6); request.setChargeType("PostPaid"); CreateCasterResponse response = client.createCaster(request); System.out.println("The production studio is created. Response: " + JSON.toJSONString(response)); return response; } private static void setCasterConfig(Client client, String casterId,String domainName) throws Exception { SetCasterConfigRequest request = new SetCasterConfigRequest(); request.setCasterId(casterId); // ドメイン名を設定します。 request.setDomainName(domainName); JSONObject transcodeConfig = new JSONObject(); JSONArray liveTemplate = new JSONArray(); //プロダクションスタジオのテンプレートを設定します。 liveTemplate.add("lld"); transcodeConfig.put("LiveTemplate", liveTemplate); //トランスコーディングテンプレートを設定します。 transcodeConfig.put("CasterTemplate", "lp_sd"); request.setTranscodeConfig(transcodeConfig.toJSONString()); SetCasterConfigResponse response = client.setCasterConfig(request); System.out.println("The production studio is configured. Response: " + JSON.toJSONString(response)); } private static StartCasterResponse startCaster(Client client, String casterId) throws Exception { StartCasterRequest startCasterRequest = new StartCasterRequest(); startCasterRequest.setCasterId(casterId); StartCasterResponse acsResponse = client.startCaster(startCasterRequest); System.out.println("The production studio is started."); return acsResponse; } private static StopCasterResponse stopCaster(Client client, String casterId) throws Exception { StopCasterRequest stopCasterRequest = new StopCasterRequest(); stopCasterRequest.setCasterId(casterId); StopCasterResponse acsResponse = client.stopCaster(stopCasterRequest); System.out.println("The production studio is stopped."); return acsResponse; } private static AddShowIntoShowListResponse addShowIntoShowList(Client client, String showName, String resourceId, String resourceUrl, String resourceType, Integer spot, Integer repeatTimes, String casterId, Long duration) throws Exception { AddShowIntoShowListRequest addShowIntoShowListRequest = new AddShowIntoShowListRequest(); if (casterId == null || resourceType == null) { return null; } if (resourceId == null && resourceUrl == null) { return null; } addShowIntoShowListRequest.setCasterId(casterId); addShowIntoShowListRequest.setResourceType(resourceType); if (showName != null) { addShowIntoShowListRequest.setShowName(showName); } if (resourceUrl != null) { addShowIntoShowListRequest.setResourceUrl(resourceUrl); } if (resourceId != null) { addShowIntoShowListRequest.setResourceId(resourceId); } if (spot != null) { addShowIntoShowListRequest.setSpot(spot); } if (repeatTimes != null) { addShowIntoShowListRequest.setRepeatTimes(repeatTimes); } if (duration != null) { addShowIntoShowListRequest.setDuration(duration); } return client.addShowIntoShowList(addShowIntoShowListRequest); } private static void removeShowFromShowList(Client client, String casterId, String showId) throws Exception { RemoveShowFromShowListRequest removeShowFromShowList = new RemoveShowFromShowListRequest(); removeShowFromShowList.setShowId(showId); removeShowFromShowList.setCasterId(casterId); RemoveShowFromShowListResponse removeShowFromShowListFromShowListResponse = client.removeShowFromShowList(removeShowFromShowList); System.out.println("removeShowFromShowListFromShowListResponse:" + JSON.toJSONString(removeShowFromShowListFromShowListResponse)); } private static void modifyShowList(Client client, String casterId, String showId, Integer repeatTimes, Integer spot, String highPriorityShowId, String highPriorityShowStartTime) throws Exception { ModifyShowListRequest modifyShowListRequest = new ModifyShowListRequest(); if (casterId != null) { modifyShowListRequest.setCasterId(casterId); } if (showId != null) { modifyShowListRequest.setShowId(showId); } if (repeatTimes != null) { modifyShowListRequest.setRepeatTimes(repeatTimes); } if (spot != null) { modifyShowListRequest.setSpot(spot); } if (highPriorityShowId != null) { modifyShowListRequest.setHighPriorityShowId(highPriorityShowId); } if (highPriorityShowStartTime != null) { modifyShowListRequest.setHighPriorityShowStartTime(highPriorityShowStartTime); } ModifyShowListResponse modifyShowListResponse = client.modifyShowList(modifyShowListRequest); System.out.println("The episode list is modified. Response: " + JSON.toJSONString(modifyShowListResponse)); } private static void describeShowList(Client client, String casterId) throws Exception { DescribeShowListRequest describeShowListRequest = new DescribeShowListRequest(); if (casterId != null) { describeShowListRequest.setCasterId(casterId); } DescribeShowListResponse describeShowListRequestResponse = client.describeShowList(describeShowListRequest); System.out.println("Query of the episode list is complete. Response parameters:" + JSON.toJSONString(describeShowListRequestResponse)); DescribeShowListResponseBody showListBody = describeShowListRequestResponse.getBody(); JSONObject showList = JSON.parseObject(showListBody.getShowList()); JSONArray shows = showList.getJSONArray("Shows"); //エピソードリスト情報を表示します。 for (int i = 0; i < shows.size(); i++) { JSONObject show = (JSONObject) shows.get(i); String showId = show.getString("ShowId"); String resourceType = show.getString("ResourceType"); String resourceInfo = show.getString("ResourceInfo"); Integer repeatTimes = show.getInteger("RepeatTimes"); Long duration = show.getLong("Duration"); String showInfo = String.format("show%d: showId: %s \n resourceType: %s \n resourceInfo: %s \n RepeatTimes: %d \n Duration: %d", i + 1, showId, resourceType, resourceInfo, repeatTimes, duration); System.out.println(showInfo); } } private static void playChoosenShow(Client client, String casterId, String showId) throws Exception { PlayChoosenShowRequest playChoosenShow = new PlayChoosenShowRequest(); playChoosenShow.setCasterId(casterId); playChoosenShow.setShowId(showId); PlayChoosenShowResponse playChoosenShowResponse = client.playChoosenShow(playChoosenShow); System.out.println("Successfully switched to showId: " + showId + "."); } private static List<DescribeCasterStreamUrlResponseBody.DescribeCasterStreamUrlResponseBodyCasterStreamsCasterStream> describeCasterStreamUrl(Client client, String casterId) throws Exception { DescribeCasterStreamUrlRequest describeCasterStreamUrlRequest = new DescribeCasterStreamUrlRequest(); describeCasterStreamUrlRequest.setCasterId(casterId); DescribeCasterStreamUrlResponse response = client.describeCasterStreamUrl(describeCasterStreamUrlRequest); return response.getBody().getCasterStreams().getCasterStream(); } public static void main(String[] args) throws Exception { Client client = LiveClient.getInstance("live.aliyuncs.com", ACCESS_KEY_ID, ACCESS_KEY_SECRET); // プロダクションスタジオを作成します。 CreateCasterResponse caster = createCaster(client); String casterId = caster.getBody().getCasterId(); // プロダクションスタジオを設定します。 String domainName = "example.aliyundoc.com"; // ドメイン名を設定します。 setCasterConfig(client, casterId,domainName); // 3 つの VOD ファイルをエピソードリストに順番に追加します。最初の VOD ファイルを 1 回、2 番目の VOD ファイルを 2 回、3 番目の VOD ファイルを 3 回再生します。 String[] resourceIds = new String[]{"698d2b23581f476ea71107703e64****", "9c97e83e211a435b9f797e4e20ee****", "76c6addaa41c438985666a8a964f****"}; for (int i = 0; i < resourceIds.length; i++) { String showName = "ShowName#" + i; Integer repeatTimes = i; addShowIntoShowList(client, showName, resourceIds[i], null, "vod", null, repeatTimes, casterId, null); } modifyShowList(client, casterId, null, 10, null, null, null); describeShowList(client, casterId); startCaster(client, casterId); Thread.sleep(500000); stopCaster(client, casterId); } }パラメーターの説明:
パラメーター設定情報
説明
private final static String ACCESS_KEY_ID = "AccessKey ID"; private final static String ACCESS_KEY_SECRET = "AccessKey Secret";ID 検証を完了するには、AccessKey ペアを使用する必要があります。AccessKey ペアは、AccessKey ID と AccessKey シークレットで構成されます。
AccessKey ID は、ユーザーの ID を検証するために使用されます。
AccessKey シークレットは、ユーザーのキーを認証するために使用されます。AccessKey シークレットは機密に保管する必要があります。
詳細については、「AccessKey ペアの作成」をご参照ください。
request.setDomainName("example.aliyundoc.com");ストリーミングドメイン。
String[] resourceIds = new String[]{"698d2b23581f476ea71107703e64****", "9c97e83e211a435b9f797e4e20ee****", "76c6addaa41c438985666a8a964f****"};リソース ID。詳細については、「2. 動画のアップロード」をご参照ください。
結果を表示します。

プロダクションスタジオ管理 ページで、作成したプロダクションスタジオを見つけ、[操作] 列の [入る] をクリックします。3 つのビデオオンデマンドファイルが順番にプレイリストに追加され、指定された設定に従って再生されます。


次のステップ
ストリームを再生するには、プロダクションスタジオの ストリーミング URL をクリックして URL をコピーします。その後、VLC メディアプレーヤー、ライブストリーミングデモ、またはプレーヤー SDK を使用して再生できます。詳細については、「ライブストリームの再生」をご参照ください。
