このトピックでは、API操作を呼び出して、プレイリストモードでプロダクションスタジオを使用する方法について説明します。 要件に合わせてコードのロジックを変更できます。
手順
次の手順を実行すると、API操作を呼び出して、プレイリストモードでプロダクションスタジオを使用できます。
サンプルコード
API操作の詳細については、「関数別の操作のリスト」をご参照ください。
次のサンプルコードでは、Go用のサーバーSDKを使用しています。 詳細については、「サーバーSDK For Goの使用」をご参照ください。
プロダクションスタジオを作成する
package caster import ( "github.com/aliyun/alibaba-cloud-sdk-go/services/live" uuid "github.com/satori/go.uuid" "testing" "github.com/go-ini/ini" ) // Create a production studio. func CreateCaster(t *testing.T) { cfg, err := ini.Load("conf/config.ini") if err != nil { t.Fatal(err) } // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. // We recommend that you not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. // In this example, the AccessKey pair is obtained from the configuration file to authenticate API accesses. For more information about the configuration file, see the following topic: ApsaraVideo Live > Developer Reference > SDK reference > Server SDKs > Use the server SDK for Go. accessKeyID := cfg.Section("").Key("access_key_id").String() accessKeySecret := cfg.Section("").Key("access_key_secret").String() liveClient, err := live.NewClientWithAccessKey("cn-shanghai", accessKeyID, accessKeySecret) if err != nil { t.Fatal(err) } // Set the request parameters for creating a production studio. createCasterRequest := live.CreateCreateCasterRequest() createCasterRequest.ClientToken = uuid.NewV1().String() createCasterRequest.CasterName = "Production studio for testing" // If the settings do not take effect, specify this parameter by calling the SetCasterConfig operation. createCasterRequest.ChargeType = "PostPaid" createCasterRequest.NormType = "6" _, err = liveClient.CreateCaster(createCasterRequest) if err != nil { t.Fatal(err) } }
CreateCaster操作のリクエストパラメーターの詳細については、「CreateCaster」をご参照ください。
プロダクションスタジオを设定する
package caster import ( "github.com/aliyun/alibaba-cloud-sdk-go/services/live" "testing" "github.com/go-ini/ini" ) // Set the production studio. func SetCasterConfig(t *testing.T) { cfg, err := ini.Load("conf/config.ini") if err != nil { t.Fatal(err) } // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. // We recommend that you not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. // In this example, the AccessKey pair is obtained from the configuration file to authenticate API accesses. For more information about the configuration file, see the following topic: ApsaraVideo Live > Developer Reference > SDK reference > Server SDKs > Use the server SDK for Go. accessKeyID := cfg.Section("").Key("access_key_id").String() accessKeySecret := cfg.Section("").Key("access_key_secret").String() liveClient, err := live.NewClientWithAccessKey("cn-shanghai", accessKeyID, accessKeySecret) if err != nil { t.Fatal(err) } // Set the request parameters for configuring the production studio. createSetCasterConfig := live.CreateSetCasterConfigRequest() createSetCasterConfig.CasterId = "xxxxxx" createSetCasterConfig.CasterName = "Production studio for testing" createSetCasterConfig.ChannelEnable = "1" createSetCasterConfig.Delay = "0" createSetCasterConfig.DomainName = "xxxxxxxx" createSetCasterConfig.ProgramEffect = "1" createSetCasterConfig.ProgramName = "test loop play" // Configure the transcoding settings. You can specify the screen orientation and resolution of videos. // For more information, see SetCasterConfig. // CasterTemplate: the transcoding settings of the production studio. Valid values: // A value of lp_ld, lp_sd, lp_hd, or lp_ud indicates that the transcoded videos are in low definition, standard definition, high definition, or ultra-high definition. // A value of lp_ld_v, lp_sd_v, lp_hd_v, or lp_ud_v indicates that the transcoded videos are in low definition, standard definition, high definition, or ultra-high definition in portrait mode. createSetCasterConfig.TranscodeConfig = `{"CasterTemplate": "lp_ld"}` // Configure the recording settings. // For more information about the JSON field, see AddLiveAppRecordConfig. createSetCasterConfig.RecordConfig = fmt.Sprintf(`{ "endpoint": "oss-cn-shanghai.aliyuncs.com", "ossBucket": "test-record", "videoFormat": [{"format": "flv", "interval": 900, "prefix":"record/{AppName}/{StreamName}/{StartTime}_{EndTime}" }]}`) _, err = liveClient.SetCasterConfig(createSetCasterConfig) if err != nil { t.Fatal(err) } }
SetCasterConfig操作の詳細については、「SetCasterConfig」をご参照ください。
エピソードリストへのエピソードの追加
package caster import ( "fmt" "github.com/aliyun/alibaba-cloud-sdk-go/services/live" "testing" "github.com/go-ini/ini" ) func TestAddShowIntoShowList(t *testing.T) { cfg, err := ini.Load("conf/config.ini") if err != nil { t.Fatal(err) } // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. // We recommend that you not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. // In this example, the AccessKey pair is obtained from the configuration file to authenticate API accesses. For more information about the configuration file, see the following topic: ApsaraVideo Live > Developer Reference > SDK reference > Server SDKs > Use the server SDK for Go. accessKeyID := cfg.Section("").Key("access_key_id").String() accessKeySecret := cfg.Section("").Key("access_key_secret").String() liveClient, err := live.NewClientWithAccessKey("cn-shanghai", accessKeyID, accessKeySecret) if err != nil { t.Fatal(err) } req := live.CreateAddShowIntoShowListRequest() req.CasterId = "xxxxx" req.ResourceType = "live" // A value of live indicates a live stream, a value of vod indicates an on-demand video, and a value of pic indicates an image. req.RegionId = "cn-shanghai" req.ShowName = "Demo for using a production studio in playlist mode" req.ResourceUrl = "xxxxxx" req.ResourceId = "" // You can specify either the RepeatTimes or Duration parameter. req.Duration = "10" // The duration of the episode. Unit: seconds. //req.RepeatTimes = "2" // The number of repetitions. For example, if you set the value to 0, the episode is played once. If you set the value to 1, the episode is played twice. //req.Spot = requests.NewInteger(0) // The position of the episode in the episode list. Position indexes start from 0. By default, the episode is added to the end of the episode list. rsp, err := liveClient.AddShowIntoShowList(req) if err != nil { t.Fatal(err) } println(fmt.Sprintf("%+v", rsp)) }
AddShowIntoShowList操作の詳細については、「AddShowIntoShowList」をご参照ください。
プロダクションスタジオを始める
package caster import ( "github.com/aliyun/alibaba-cloud-sdk-go/services/live" "testing" "time" "github.com/go-ini/ini" ) // Start the production studio and set the playback scenes. func StartCaster(t *testing.T) { cfg, err := ini.Load("conf/config.ini") if err != nil { t.Fatal(err) } // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. // We recommend that you not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. // In this example, the AccessKey pair is obtained from the configuration file to authenticate API accesses. For more information about the configuration file, see the following topic: ApsaraVideo Live > Developer Reference > SDK reference > Server SDKs > Use the server SDK for Go. accessKeyID := cfg.Section("").Key("access_key_id").String() accessKeySecret := cfg.Section("").Key("access_key_secret").String() liveClient, err := live.NewClientWithAccessKey("cn-shanghai", accessKeyID, accessKeySecret) if err != nil { t.Fatal(err) } // Start the production studio. startCasterRequest := live.CreateStartCasterRequest() startCasterRequest.CasterId = "xxx" startCasterResp, err := liveClient.StartCaster(startCasterRequest) if err != nil { t.Fatal(err) } // Suspend code execution before the required resources are loaded. If you immediately start the production studio, specific resources may fail to be loaded. time.Sleep(time.Second) // Set the playback scenes. // (Optional) Set a PVW scene. setCasterSceneConfigRequest := live.CreateSetCasterSceneConfigRequest() setCasterSceneConfigRequest.LayoutId = "xxx" setCasterSceneConfigRequest.CasterId = "xxx" setCasterSceneConfigRequest.SceneId = startCasterResp.PvwSceneInfos.SceneInfo[0].SceneId _, err = liveClient.SetCasterSceneConfig(setCasterSceneConfigRequest) if err != nil { t.Fatal(err) } // (Required) Set a PGM scene. setCasterSceneConfigRequest.SceneId = startCasterResp.PgmSceneInfos.SceneInfo[0].SceneId _, err = liveClient.SetCasterSceneConfig(setCasterSceneConfigRequest) if err != nil { t.Fatal(err) } }
StartCaster操作の詳細については、「StartCaster」をご参照ください。
SetCasterSceneConfig操作の詳細については、「SetCasterSceneConfig」をご参照ください。
指定したエピソードに切り替える
package caster import ( "fmt" "github.com/aliyun/alibaba-cloud-sdk-go/services/live" "testing" "github.com/go-ini/ini" ) func TestPlayChoosenShow(t *testing.T) { cfg, err := ini.Load("conf/config.ini") if err != nil { t.Fatal(err) } // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. // We recommend that you not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. // In this example, the AccessKey pair is obtained from the configuration file to authenticate API accesses. For more information about the configuration file, see the following topic: ApsaraVideo Live > Developer Reference > SDK reference > Server SDKs > Use the server SDK for Go. accessKeyID := cfg.Section("").Key("access_key_id").String() accessKeySecret := cfg.Section("").Key("access_key_secret").String() liveClient, err := live.NewClientWithAccessKey("cn-shanghai", accessKeyID, accessKeySecret) if err != nil { t.Fatal(err) } req := live.CreatePlayChoosenShowRequest() req.CasterId = "xxxxx" req.ShowId = "xxxxx" req.RegionId = "cn-shanghai" rsp, err := liveClient.PlayChoosenShow(req) if err != nil { t.Fatal(err) } println(fmt.Sprintf("%+v", rsp)) }
PlayChoosenShow操作の詳細については、「PlayChoosenShow」をご参照ください。
プロダクションスタジオを停止する
package caster import ( "github.com/aliyun/alibaba-cloud-sdk-go/services/live" "testing" "github.com/go-ini/ini" ) // Stop the production studio. func StopCaster(t *testing.T) { cfg, err := ini.Load("conf/config.ini") if err != nil { t.Fatal(err) } // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. // We recommend that you not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. // In this example, the AccessKey pair is obtained from the configuration file to authenticate API accesses. For more information about the configuration file, see the following topic: ApsaraVideo Live > Developer Reference > SDK reference > Server SDKs > Use the server SDK for Go. accessKeyID := cfg.Section("").Key("access_key_id").String() accessKeySecret := cfg.Section("").Key("access_key_secret").String() liveClient, err := live.NewClientWithAccessKey("cn-shanghai", accessKeyID, accessKeySecret) if err != nil { t.Fatal(err) } // Stop the production studio. stopCasterRequest := live.CreateStopCasterRequest() stopCasterRequest.CasterId = "xxxx" _, err = liveClient.StopCaster(stopCasterRequest) if err != nil { t.Fatal(err) } }
StopCaster操作の詳細については、「StopCaster」をご参照ください。
プロダクションスタジオの削除
package caster import ( "github.com/aliyun/alibaba-cloud-sdk-go/services/live" "testing" "github.com/go-ini/ini" ) // Delete the production studio. func DeleteCaster(t *testing.T) { cfg, err := ini.Load("conf/config.ini") if err != nil { t.Fatal(err) } // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. // We recommend that you not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. // In this example, the AccessKey pair is obtained from the configuration file to authenticate API accesses. For more information about the configuration file, see the following topic: ApsaraVideo Live > Developer Reference > SDK reference > Server SDKs > Use the server SDK for Go. accessKeyID := cfg.Section("").Key("access_key_id").String() accessKeySecret := cfg.Section("").Key("access_key_secret").String() liveClient, err := live.NewClientWithAccessKey("cn-shanghai", accessKeyID, accessKeySecret) if err != nil { t.Fatal(err) } // Delete the production studio. deleteCasterRequest := live.CreateDeleteCasterRequest() deleteCasterRequest.CasterId = "xxxxxxx" _, err = liveClient.DeleteCaster(deleteCasterRequest) if err != nil { t.Fatal(err) } }
DeleteCaster操作の詳細については、「DeleteCaster」をご参照ください。
スケジュール済みタスクの作成
package caster import ( "fmt" "github.com/aliyun/alibaba-cloud-sdk-go/services/live" "github.com/go-ini/ini" "testing" ) func InitializeAutoShowListTask(t *testing.T) { cfg, err := ini.Load("conf/config.ini") if err != nil { t.Fatal(err) } // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. // We recommend that you not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. // In this example, the AccessKey pair is obtained from the configuration file to authenticate API accesses. For more information about the configuration file, see the following topic: ApsaraVideo Live > Developer Reference > SDK reference > Server SDKs > Use the server SDK for Go. accessKeyID := cfg.Section("").Key("access_key_id").String() accessKeySecret := cfg.Section("").Key("access_key_secret").String() liveClient, err := live.NewClientWithAccessKey("cn-shanghai", accessKeyID, accessKeySecret) if err != nil { t.Fatal(err) } req := live.CreateInitializeAutoShowListTaskRequest() req.CasterConfig = `{"CasterTemplate": "lp_ld","LiveTemplates":["lhd", "lsd","lud"]}` req.DomainName = `xxxx-xxxx.xxxxx.com` req.ResourceIds = `["xxxxx"]` // View the media library in the ApsaraVideo VOD console. req.StartTime = "1660632600000" // The timestamp when the task starts, in milliseconds. req.EndTime = "1660632660000" // The timestamp when the task ends, in milliseconds. rsp, err := liveClient.InitializeAutoShowListTask(req) if err != nil { t.Fatal(err) } println(fmt.Sprintf("%+v", rsp)) }
InitializeAutoShowListTask操作の詳細については、「InitializeAutoShowListTask」をご参照ください。
エピソードリストからエピソードを削除する
package caster import ( "fmt" "github.com/aliyun/alibaba-cloud-sdk-go/services/live" "github.com/go-ini/ini" "testing" ) func RemoveShowFromShowList(t *testing.T) { cfg, err := ini.Load("conf/config.ini") if err != nil { t.Fatal(err) } // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. // We recommend that you not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. // In this example, the AccessKey pair is obtained from the configuration file to authenticate API accesses. For more information about the configuration file, see the following topic: ApsaraVideo Live > Developer Reference > SDK reference > Server SDKs > Use the server SDK for Go. accessKeyID := cfg.Section("").Key("access_key_id").String() accessKeySecret := cfg.Section("").Key("access_key_secret").String() liveClient, err := live.NewClientWithAccessKey("cn-shanghai", accessKeyID, accessKeySecret) if err != nil { t.Fatal(err) } req := live.CreateRemoveShowFromShowListRequest() req.CasterId = "xxxx" req.ShowId = "xxxxx" // The episode ID. Take note that you cannot remove an episode that is being played. req.RegionId = "cn-shanghai" rsp, err := liveClient.RemoveShowFromShowList(req) if err != nil { t.Fatal(err) } println(fmt.Sprintf("%+v", rsp)) }
RemoveShowFromShowList操作の詳細については、「RemoveShowFromShowList」をご参照ください。
エピソードリストの属性の変更
package caster import ( "fmt" "github.com/aliyun/alibaba-cloud-sdk-go/services/live" "github.com/go-ini/ini" "testing" ) func ModifyShowList(t *testing.T) { cfg, err := ini.Load("conf/config.ini") if err != nil { t.Fatal(err) } // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. // We recommend that you not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. // In this example, the AccessKey pair is obtained from the configuration file to authenticate API accesses. For more information about the configuration file, see the following topic: ApsaraVideo Live > Developer Reference > SDK reference > Server SDKs > Use the server SDK for Go. accessKeyID := cfg.Section("").Key("access_key_id").String() accessKeySecret := cfg.Section("").Key("access_key_secret").String() liveClient, err := live.NewClientWithAccessKey("cn-shanghai", accessKeyID, accessKeySecret) if err != nil { t.Fatal(err) } req := live.CreateModifyShowListRequest() req.CasterId = "xxxx" req.RegionId = "cn-shanghai" req.RepeatTimes = "2" // The number of repetitions. For example, if you set the value to 0, the episode is played once. If you set the value to 1, the episode is played twice. //req.ShowId = "xxxx" //req.Spot = "0" // The position of the episode in the episode list. Position indexes start from 0. By default, the episode is added to the end of the episode list. rsp, err := liveClient.ModifyShowList(req) if err != nil { t.Fatal(err) } println(fmt.Sprintf("%+v", rsp)) }
ModifyShowList操作の詳細については、「ModifyShowList」をご参照ください。
エピソードリストの詳細の照会
package caster import ( "fmt" "github.com/aliyun/alibaba-cloud-sdk-go/services/live" "github.com/go-ini/ini" "testing" ) func TestDescribeShowList(t *testing.T) { cfg, err := ini.Load("conf/config.ini") if err != nil { t.Fatal(err) } // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. // We recommend that you not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. // In this example, the AccessKey pair is obtained from the configuration file to authenticate API accesses. For more information about the configuration file, see the following topic: ApsaraVideo Live > Developer Reference > SDK reference > Server SDKs > Use the server SDK for Go. accessKeyID := cfg.Section("").Key("access_key_id").String() accessKeySecret := cfg.Section("").Key("access_key_secret").String() liveClient, err := live.NewClientWithAccessKey("cn-shanghai", accessKeyID, accessKeySecret) if err != nil { t.Fatal(err) } req := live.CreateDescribeShowListRequest() req.CasterId = "xxxxxx" req.RegionId = "cn-shanghai" rsp, _ := liveClient.DescribeShowList(req) if err != nil { // In case of an error, both the error message and the result are returned. Ignore the error message. t.Fatal(err) } println(fmt.Sprintf("%+v", rsp)) }
DescribeShowList操作の詳細については、「DescribeShowList」をご参照ください。
エピソードリストの再生を開始および停止するために作成されたスケジュール済みタスクの照会
package caster import ( "fmt" "github.com/aliyun/alibaba-cloud-sdk-go/services/live" "github.com/go-ini/ini" "testing" ) func DescribeAutoShowListTasks(t *testing.T) { cfg, err := ini.Load("conf/config.ini") if err != nil { t.Fatal(err) } // The AccessKey pair of an Alibaba Cloud account has access permissions on all API operations. We recommend that you use the AccessKey pair of a RAM user to call API operations or perform routine O&M. // We recommend that you not save your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all resources within your account may be compromised. // In this example, the AccessKey pair is obtained from the configuration file to authenticate API accesses. For more information about the configuration file, see the following topic: ApsaraVideo Live > Developer Reference > SDK reference > Server SDKs > Use the server SDK for Go. accessKeyID := cfg.Section("").Key("access_key_id").String() accessKeySecret := cfg.Section("").Key("access_key_secret").String() liveClient, err := live.NewClientWithAccessKey("cn-shanghai", accessKeyID, accessKeySecret) if err != nil { t.Fatal(err) } req := live.CreateDescribeAutoShowListTasksRequest() req.CasterId = "xxxx" rsp, err := liveClient.DescribeAutoShowListTasks(req) if err != nil { t.Fatal(err) } println(fmt.Sprintf("%+v", rsp)) }
DescribeAutoShowListTasks操作の詳細については、「DescribeAutoShowListTasks」をご参照ください。