Skip to content

Commit eaef7c2

Browse files
authored
feat: add Video Stitcher VOD session code samples and tests (GoogleCloudPlatform#7176)
* feat: add Video Stitcher VOD session code samples and tests * fix lint error
1 parent 72b2f4e commit eaef7c2

12 files changed

Lines changed: 915 additions & 0 deletions
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.stitcher;
18+
19+
// [START video_stitcher_create_vod_session]
20+
21+
import com.google.cloud.video.stitcher.v1.CreateVodSessionRequest;
22+
import com.google.cloud.video.stitcher.v1.LocationName;
23+
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
24+
import com.google.cloud.video.stitcher.v1.VodSession;
25+
import java.io.IOException;
26+
27+
public class CreateVodSession {
28+
29+
public static void main(String[] args) throws Exception {
30+
// TODO(developer): Replace these variables before running the sample.
31+
String projectId = "my-project-id";
32+
String location = "us-central1";
33+
// Uri of the media to stitch; this URI must reference either an MPEG-DASH
34+
// manifest (.mpd) file or an M3U playlist manifest (.m3u8) file.
35+
String sourceUri = "https://storage.googleapis.com/my-bucket/main.mpd";
36+
// See VMAP Pre-roll
37+
// (https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/tags)
38+
String adTagUri = "https://pubads.g.doubleclick.net/gampad/ads...";
39+
createVodSession(projectId, location, sourceUri, adTagUri);
40+
}
41+
42+
public static void createVodSession(
43+
String projectId, String location, String sourceUri, String adTagUri) throws IOException {
44+
// Initialize client that will be used to send requests. This client only needs to be created
45+
// once, and can be reused for multiple requests. After completing all of your requests, call
46+
// the "close" method on the client to safely clean up any remaining background resources.
47+
try (VideoStitcherServiceClient videoStitcherServiceClient =
48+
VideoStitcherServiceClient.create()) {
49+
CreateVodSessionRequest createVodSessionRequest =
50+
CreateVodSessionRequest.newBuilder()
51+
.setParent(LocationName.of(projectId, location).toString())
52+
.setVodSession(
53+
VodSession.newBuilder().setSourceUri(sourceUri).setAdTagUri(adTagUri).build())
54+
.build();
55+
56+
VodSession response = videoStitcherServiceClient.createVodSession(createVodSessionRequest);
57+
System.out.println("Created VOD session: " + response.getName());
58+
}
59+
}
60+
}
61+
// [END video_stitcher_create_vod_session]
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.stitcher;
18+
19+
// [START video_stitcher_get_vod_ad_tag_detail]
20+
21+
import com.google.cloud.video.stitcher.v1.GetVodAdTagDetailRequest;
22+
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
23+
import com.google.cloud.video.stitcher.v1.VodAdTagDetail;
24+
import com.google.cloud.video.stitcher.v1.VodAdTagDetailName;
25+
import java.io.IOException;
26+
27+
public class GetVodAdTagDetail {
28+
29+
public static void main(String[] args) throws Exception {
30+
// TODO(developer): Replace these variables before running the sample.
31+
String projectId = "my-project-id";
32+
String location = "us-central1";
33+
String sessionId = "my-session-id";
34+
String adTagDetailId = "my-ad-tag-id";
35+
36+
getVodAdTagDetail(projectId, location, sessionId, adTagDetailId);
37+
}
38+
39+
public static void getVodAdTagDetail(
40+
String projectId, String location, String sessionId, String adTagDetailId)
41+
throws IOException {
42+
// Initialize client that will be used to send requests. This client only needs to be created
43+
// once, and can be reused for multiple requests. After completing all of your requests, call
44+
// the "close" method on the client to safely clean up any remaining background resources.
45+
try (VideoStitcherServiceClient videoStitcherServiceClient =
46+
VideoStitcherServiceClient.create()) {
47+
GetVodAdTagDetailRequest getVodAdTagDetailRequest =
48+
GetVodAdTagDetailRequest.newBuilder()
49+
.setName(
50+
VodAdTagDetailName.of(projectId, location, sessionId, adTagDetailId).toString())
51+
.build();
52+
53+
VodAdTagDetail response =
54+
videoStitcherServiceClient.getVodAdTagDetail(getVodAdTagDetailRequest);
55+
System.out.println("VOD ad tag detail: " + response.getName());
56+
}
57+
}
58+
}
59+
// [END video_stitcher_get_vod_ad_tag_detail]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.stitcher;
18+
19+
// [START video_stitcher_get_vod_session]
20+
21+
import com.google.cloud.video.stitcher.v1.GetVodSessionRequest;
22+
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
23+
import com.google.cloud.video.stitcher.v1.VodSession;
24+
import com.google.cloud.video.stitcher.v1.VodSessionName;
25+
import java.io.IOException;
26+
27+
public class GetVodSession {
28+
29+
public static void main(String[] args) throws Exception {
30+
// TODO(developer): Replace these variables before running the sample.
31+
String projectId = "my-project-id";
32+
String location = "us-central1";
33+
String sessionId = "my-session-id";
34+
35+
getVodSession(projectId, location, sessionId);
36+
}
37+
38+
public static void getVodSession(String projectId, String location, String sessionId)
39+
throws IOException {
40+
// Initialize client that will be used to send requests. This client only needs to be created
41+
// once, and can be reused for multiple requests. After completing all of your requests, call
42+
// the "close" method on the client to safely clean up any remaining background resources.
43+
try (VideoStitcherServiceClient videoStitcherServiceClient =
44+
VideoStitcherServiceClient.create()) {
45+
GetVodSessionRequest getVodSessionRequest =
46+
GetVodSessionRequest.newBuilder()
47+
.setName(VodSessionName.of(projectId, location, sessionId).toString())
48+
.build();
49+
50+
VodSession response = videoStitcherServiceClient.getVodSession(getVodSessionRequest);
51+
System.out.println("VOD session: " + response.getName());
52+
}
53+
}
54+
}
55+
// [END video_stitcher_get_vod_session]
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.stitcher;
18+
19+
// [START video_stitcher_get_vod_stitch_detail]
20+
21+
import com.google.cloud.video.stitcher.v1.GetVodStitchDetailRequest;
22+
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
23+
import com.google.cloud.video.stitcher.v1.VodStitchDetail;
24+
import com.google.cloud.video.stitcher.v1.VodStitchDetailName;
25+
import java.io.IOException;
26+
27+
public class GetVodStitchDetail {
28+
29+
public static void main(String[] args) throws Exception {
30+
// TODO(developer): Replace these variables before running the sample.
31+
String projectId = "my-project-id";
32+
String location = "us-central1";
33+
String sessionId = "my-session-id";
34+
String stitchDetailId = "my-stitch-id";
35+
36+
getVodStitchDetail(projectId, location, sessionId, stitchDetailId);
37+
}
38+
39+
public static void getVodStitchDetail(
40+
String projectId, String location, String sessionId, String stitchDetailId)
41+
throws IOException {
42+
// Initialize client that will be used to send requests. This client only needs to be created
43+
// once, and can be reused for multiple requests. After completing all of your requests, call
44+
// the "close" method on the client to safely clean up any remaining background resources.
45+
try (VideoStitcherServiceClient videoStitcherServiceClient =
46+
VideoStitcherServiceClient.create()) {
47+
GetVodStitchDetailRequest getVodStitchDetailRequest =
48+
GetVodStitchDetailRequest.newBuilder()
49+
.setName(
50+
VodStitchDetailName.of(projectId, location, sessionId, stitchDetailId).toString())
51+
.build();
52+
53+
VodStitchDetail response =
54+
videoStitcherServiceClient.getVodStitchDetail(getVodStitchDetailRequest);
55+
System.out.println("VOD stitch detail: " + response.getName());
56+
}
57+
}
58+
}
59+
// [END video_stitcher_get_vod_stitch_detail]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.stitcher;
18+
19+
// [START video_stitcher_list_vod_ad_tag_details]
20+
21+
import com.google.cloud.video.stitcher.v1.ListVodAdTagDetailsRequest;
22+
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
23+
import com.google.cloud.video.stitcher.v1.VodAdTagDetail;
24+
import com.google.cloud.video.stitcher.v1.VodSessionName;
25+
import java.io.IOException;
26+
27+
public class ListVodAdTagDetails {
28+
29+
public static void main(String[] args) throws Exception {
30+
// TODO(developer): Replace these variables before running the sample.
31+
String projectId = "my-project-id";
32+
String location = "us-central1";
33+
String sessionId = "my-session-id";
34+
35+
listVodAdTagDetails(projectId, location, sessionId);
36+
}
37+
38+
public static void listVodAdTagDetails(String projectId, String location, String sessionId)
39+
throws IOException {
40+
// Initialize client that will be used to send requests. This client only needs to be created
41+
// once, and can be reused for multiple requests. After completing all of your requests, call
42+
// the "close" method on the client to safely clean up any remaining background resources.
43+
try (VideoStitcherServiceClient videoStitcherServiceClient =
44+
VideoStitcherServiceClient.create()) {
45+
ListVodAdTagDetailsRequest listVodAdTagDetailsRequest =
46+
ListVodAdTagDetailsRequest.newBuilder()
47+
.setParent(VodSessionName.of(projectId, location, sessionId).toString())
48+
.build();
49+
50+
VideoStitcherServiceClient.ListVodAdTagDetailsPagedResponse response =
51+
videoStitcherServiceClient.listVodAdTagDetails(listVodAdTagDetailsRequest);
52+
System.out.println("VOD ad tag details:");
53+
54+
for (VodAdTagDetail adTagDetail : response.iterateAll()) {
55+
System.out.println(adTagDetail.toString());
56+
}
57+
}
58+
}
59+
}
60+
// [END video_stitcher_list_vod_ad_tag_details]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.stitcher;
18+
19+
// [START video_stitcher_list_vod_stitch_details]
20+
21+
import com.google.cloud.video.stitcher.v1.ListVodStitchDetailsRequest;
22+
import com.google.cloud.video.stitcher.v1.VideoStitcherServiceClient;
23+
import com.google.cloud.video.stitcher.v1.VodSessionName;
24+
import com.google.cloud.video.stitcher.v1.VodStitchDetail;
25+
import java.io.IOException;
26+
27+
public class ListVodStitchDetails {
28+
29+
public static void main(String[] args) throws Exception {
30+
// TODO(developer): Replace these variables before running the sample.
31+
String projectId = "my-project-id";
32+
String location = "us-central1";
33+
String sessionId = "my-session-id";
34+
35+
listVodStitchDetails(projectId, location, sessionId);
36+
}
37+
38+
public static void listVodStitchDetails(String projectId, String location, String sessionId)
39+
throws IOException {
40+
// Initialize client that will be used to send requests. This client only needs to be created
41+
// once, and can be reused for multiple requests. After completing all of your requests, call
42+
// the "close" method on the client to safely clean up any remaining background resources.
43+
try (VideoStitcherServiceClient videoStitcherServiceClient =
44+
VideoStitcherServiceClient.create()) {
45+
ListVodStitchDetailsRequest listVodStitchDetailsRequest =
46+
ListVodStitchDetailsRequest.newBuilder()
47+
.setParent(VodSessionName.of(projectId, location, sessionId).toString())
48+
.build();
49+
50+
VideoStitcherServiceClient.ListVodStitchDetailsPagedResponse response =
51+
videoStitcherServiceClient.listVodStitchDetails(listVodStitchDetailsRequest);
52+
System.out.println("VOD stitch details:");
53+
54+
for (VodStitchDetail stitchDetail : response.iterateAll()) {
55+
System.out.println(stitchDetail.toString());
56+
}
57+
}
58+
}
59+
}
60+
// [END video_stitcher_list_vod_stitch_details]

0 commit comments

Comments
 (0)