|
| 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] |
0 commit comments