当我使用 Java youtube api 上传视频时,是否可以向视频添加注释或“结束画面"? [英] Is possible to add annotations or a 'end screen' to a video when i'm uploading it using Java youtube api?

查看:24
本文介绍了当我使用 Java youtube api 上传视频时,是否可以向视频添加注释或“结束画面"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了生成我的代码,我修改了从 google 放到 gitHub 上的示例.

For generate my code I modified the samples putted from google on gitHub.

一切顺利,视频上传没有问题,但现在我需要为我的视频添加一些注释或结束画面",因为我需要在用户看到我的视频预览"后将他们重定向到我的网站.

All Goes ok and the video upload has no problem but now I need to put some annotations or a 'end screen' to my videos because I need to redirect users to my site after they have seen my 'video preview'.

所以,工作流程是这样的:

So, the workflow is something like this:

1) 用户从一个 jsp 页面插入标题和描述.

1) The user inserts title and description from a jsp page.

2) 当他点击按钮时,软件会获取存储在我的数据库中的用户凭据,然后将所有参数传递给我在下面发布的方法.

2) When he clicks on the button the software take the credentials of the user stored in my db and then pass all the parameters to the method i posted below.

3) 班级将视频上传到 YouTube.

3) the class uploads the video to YouTube.

现在我的问题是:有没有一种简单的方法可以将我的链接附加"到上传的视频中?

Now my question is: there is an easy way to 'attach' my links to the uploaded video?

我应该在视频区域使用诸如注释、号召性用语或任何类型的叠加消息/按钮之类的内容.

I should use something like annotations, call-to-action or any kind of overlay message/button on the video area.

覆盖是在整个视频持续时间内持续存在还是仅出现在视频末尾都没有关系.

It doesn't matter if the overlay persists for all the video duration or it appears only at the end of the video.

希望有人能帮帮我!我希望谷歌能以更好的方式重写文档,因为我对实现 YouTube 的 API 变得疯狂.

I hope someone can help me! And i hope google will rewrites the documentation in a better way because i became crazy for implements YouTube's API.

这是我的源代码片段:

    public static void upload( String jsonString, String videoPath, String title , String description, String articleTags, HttpServletRequest request) {

    // This OAuth 2.0 access scope allows an application to upload files
    // to the authenticated user's YouTube channel, but doesn't allow
    // other types of access.
    List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.upload");

    try {

        // Authorize the request.
        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"));


        // This object is used to make YouTube Data API requests.
        youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).setApplicationName("virtual-cms-video-upload").build();

        System.out.println("Uploading: " + videoPath);

        // Add extra information to the video before uploading.
        Video videoObjectDefiningMetadata = new Video();

        // Set the video to be publicly visible. This is the default
        // setting. Other supporting settings are "unlisted" and "private."
        VideoStatus status = new VideoStatus();
        status.setPrivacyStatus("public");
        videoObjectDefiningMetadata.setStatus(status);



        // Most of the video's metadata is set on the VideoSnippet object.
        VideoSnippet snippet = new VideoSnippet();

        // This code uses a Calendar instance to create a unique name and
        // description for test purposes so that you can easily upload
        // multiple files. You should remove this code from your project
        // and use your own standard names instead.
        snippet.setTitle      (title      );
        snippet.setDescription(description);



        if( !articleTags.trim().equals("") ){            

            // Set the keyword tags that you want to associate with the video.
            List<String> tags = new ArrayList<String>();

            for(int i = 0; i < articleTags.split(",").length ; i++){

                tags.add(articleTags);

            }

            snippet.setTags(tags);

            // Add the completed snippet object to the video resource.
            videoObjectDefiningMetadata.setSnippet(snippet);

        }

        //InputStreamContent mediaContent = new InputStreamContent(VIDEO_FILE_FORMAT,UploadYouTubeVideo.class.getClassLoader().getResourceAsStream(videoPath));
        InputStreamContent mediaContent = new InputStreamContent(VIDEO_FILE_FORMAT,new java.io.FileInputStream(new File(videoPath)));

        // Insert the video. The command sends three arguments. The first
        // specifies which information the API request is setting and which
        // information the API response should return. The second argument
        // is the video resource that contains metadata about the new video.
        // The third argument is the actual video content.
        YouTube.Videos.Insert videoInsert = youtube.videos().insert("snippet,statistics,status", videoObjectDefiningMetadata, mediaContent);

        // Set the upload type and add an event listener.
        MediaHttpUploader uploader = videoInsert.getMediaHttpUploader();

        // Indicate whether direct media upload is enabled. A value of
        // "True" indicates that direct media upload is enabled and that
        // the entire media content will be uploaded in a single request.
        // A value of "False," which is the default, indicates that the
        // request will use the resumable media upload protocol, which
        // supports the ability to resume an upload operation after a
        // network interruption or other transmission failure, saving
        // time and bandwidth in the event of network failures.
        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);

        // Call the API and upload the video.
        Video returnedVideo = videoInsert.execute();

        // Print data about the newly inserted video from the API response.
        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();
    }
}

推荐答案

不幸的是,这是不可能的,据我所知也永远不会.

Unfortunately, it is not possible, nor will it ever be as far as i can tell.

无法添加注释是一种预期行为.请参阅此链接:https://issuetracker.google.com/issues/35166657 - 状态:无法修复(预期行为)

Not being able to add annotations is an intended behaviour. See this link: https://issuetracker.google.com/issues/35166657 - Status: Won't Fix (Intended behavior)

显然最好的选择是 InVideo 编程,但我认为这不适合您的目的,除非它可以是特定于视频的.

Apparently the best alternative is InVideo Programming but i do not believe this is suitable for your purpose, unless it can be video specific.

这篇关于当我使用 Java youtube api 上传视频时,是否可以向视频添加注释或“结束画面"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆