@@ -50,7 +50,10 @@ public static void main(String[] args) throws Exception {
5050 createLiveConfig (projectId , location , liveConfigId , sourceUri , adTagUri , slateId );
5151 }
5252
53- public static void createLiveConfig (
53+ // Creates a live config. Live configs are used to configure live sessions.
54+ // For more information, see
55+ // https://cloud.google.com/video-stitcher/docs/how-to/managing-live-configs.
56+ public static LiveConfig createLiveConfig (
5457 String projectId ,
5558 String location ,
5659 String liveConfigId ,
@@ -59,29 +62,30 @@ public static void createLiveConfig(
5962 String slateId )
6063 throws IOException , ExecutionException , InterruptedException , TimeoutException {
6164 // Initialize client that will be used to send requests. This client only needs to be created
62- // once, and can be reused for multiple requests. After completing all of your requests, call
63- // the "close" method on the client to safely clean up any remaining background resources.
64- VideoStitcherServiceClient videoStitcherServiceClient = VideoStitcherServiceClient .create ();
65- CreateLiveConfigRequest createLiveConfigRequest =
66- CreateLiveConfigRequest .newBuilder ()
67- .setParent (LocationName .of (projectId , location ).toString ())
68- .setLiveConfigId (liveConfigId )
69- .setLiveConfig (
70- LiveConfig .newBuilder ()
71- .setSourceUri (sourceUri )
72- .setAdTagUri (adTagUri )
73- .setDefaultSlate (SlateName .format (projectId , location , slateId ))
74- .setAdTracking (AdTracking .SERVER )
75- .setStitchingPolicy (StitchingPolicy .CUT_CURRENT )
76- .build ())
77- .build ();
65+ // once, and can be reused for multiple requests.
66+ try ( VideoStitcherServiceClient videoStitcherServiceClient =
67+ VideoStitcherServiceClient .create ()) {
68+ CreateLiveConfigRequest createLiveConfigRequest =
69+ CreateLiveConfigRequest .newBuilder ()
70+ .setParent (LocationName .of (projectId , location ).toString ())
71+ .setLiveConfigId (liveConfigId )
72+ .setLiveConfig (
73+ LiveConfig .newBuilder ()
74+ .setSourceUri (sourceUri )
75+ .setAdTagUri (adTagUri )
76+ .setDefaultSlate (SlateName .format (projectId , location , slateId ))
77+ .setAdTracking (AdTracking .SERVER )
78+ .setStitchingPolicy (StitchingPolicy .CUT_CURRENT )
79+ .build ())
80+ .build ();
7881
79- LiveConfig response =
80- videoStitcherServiceClient
81- .createLiveConfigAsync (createLiveConfigRequest )
82- .get (TIMEOUT_IN_MINUTES , TimeUnit .MINUTES );
83- System .out .println ("Created new live config: " + response .getName ());
84- videoStitcherServiceClient .close ();
82+ LiveConfig response =
83+ videoStitcherServiceClient
84+ .createLiveConfigAsync (createLiveConfigRequest )
85+ .get (TIMEOUT_IN_MINUTES , TimeUnit .MINUTES );
86+ System .out .println ("Created new live config: " + response .getName ());
87+ return response ;
88+ }
8589 }
8690}
8791// [END videostitcher_create_live_config]
0 commit comments