To generate my code, I modified the samples posted from google to gitHub.
Everything is working fine and there’s no problem downloading the video, but now I need to add some annotations or an “end screen” to my videos because I need to redirect users to my site after they see my “preview video”.
So, the workflow looks something like this:
1) The user inserts a title and description from the jsp page.
2) When he clicks on the button, the software takes the credentials of the user stored in my database, and then passes all the parameters to the method indicated below.
3) the class uploads the video to YouTube.
Now my question is: is there an easy way to “attach” my links to the downloaded video?
I should use something like annotations, a call to action, or any type of overlay message / button in the video area.
It does not matter if the overlay is saved for the entire duration of the video or appears only at the end of the video.
Hope someone can help me! And I hope that Google will rewrite the documentation better, because I became crazy for implementing the YouTube API.
This is a piece of source code:
public static void upload( String jsonString, String videoPath, String title , String description, String articleTags, HttpServletRequest request) {
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.upload");
try {
JSONObject jsonObj = new JSONObject(jsonString);
GoogleCredential credential = new GoogleCredential.Builder()
.setClientSecrets(jsonObj.getString("client_id"), jsonObj.getString("client_secret"))
.setJsonFactory(Auth.JSON_FACTORY).setTransport(Auth.HTTP_TRANSPORT).build()
.setRefreshToken(jsonObj.getString("refresh_token")).setAccessToken(jsonObj.getString("access_token"));
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("virtual-cms-video-upload").build();
System.out.println("Uploading: " + videoPath);
Video videoObjectDefiningMetadata = new Video();
VideoStatus status = new VideoStatus();
status.setPrivacyStatus("public");
videoObjectDefiningMetadata.setStatus(status);
VideoSnippet snippet = new VideoSnippet();
snippet.setTitle (title );
snippet.setDescription(description);
if( !articleTags.trim().equals("") ){
List<String> tags = new ArrayList<String>();
for(int i = 0; i < articleTags.split(",").length ; i++){
tags.add(articleTags);
}
snippet.setTags(tags);
videoObjectDefiningMetadata.setSnippet(snippet);
}
InputStreamContent mediaContent = new InputStreamContent(VIDEO_FILE_FORMAT,new java.io.FileInputStream(new File(videoPath)));
YouTube.Videos.Insert videoInsert = youtube.videos().insert("snippet,statistics,status", videoObjectDefiningMetadata, mediaContent);
MediaHttpUploader uploader = videoInsert.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false);
MediaHttpUploaderProgressListener progressListener = new MediaHttpUploaderProgressListener() {
public void progressChanged(MediaHttpUploader uploader) throws IOException {
switch (uploader.getUploadState()) {
case INITIATION_STARTED:
System.out.println("Initiation Started");
break;
case INITIATION_COMPLETE:
System.out.println("Initiation Completed");
break;
case MEDIA_IN_PROGRESS:
System.out.println("Upload in progress");
System.out.println("Upload percentage: " + uploader.getProgress());
break;
case MEDIA_COMPLETE:
System.out.println("Upload Completed!");
break;
case NOT_STARTED:
System.out.println("Upload Not Started!");
break;
}
}
};
uploader.setProgressListener(progressListener);
Video returnedVideo = videoInsert.execute();
System.out.println("\n================== Returned Video ==================\n");
System.out.println(" - Id : " + returnedVideo.getId() );
System.out.println(" - Title : " + returnedVideo.getSnippet().getTitle() );
System.out.println(" - Tags : " + returnedVideo.getSnippet().getTags() );
System.out.println(" - Privacy Status: " + returnedVideo.getStatus().getPrivacyStatus());
System.out.println(" - Video Count : " + returnedVideo.getStatistics().getViewCount());
} catch (Exception ex) {
System.err.println("Throwable: " + ex.getMessage());
ex.printStackTrace();
}
}