2017-10-12 10 views
6

내 코드를 생성하기 위해 gitHub에서 go putted 샘플을 수정했습니다.자바 유튜브 API를 사용하여 업로드 할 때 동영상에 특수 효과 또는 '최종 화면'을 추가 할 수 있습니까?

모두 괜찮습니다. 동영상 업로드에는 아무런 문제가 없지만 내 '동영상 미리보기'를 본 후 사용자를 내 사이트로 리디렉션해야하므로 동영상에 일부 특수 효과 또는 '종료 화면'을 넣어야합니다. JSP 페이지에서

1) 사용자 삽입 제목 및 설명 :

그래서 워크 플로는이 같은 것입니다.

2) 버튼을 클릭하면 소프트웨어가 내 DB에 저장된 사용자의 자격증을 가져 와서 모든 매개 변수를 아래 게시 된 방법으로 전달합니다.

3) 클래스가 YouTube에 비디오를 업로드합니다.

이제 내 질문 : 업로드 된 비디오에 내 링크를 '첨부'하는 쉬운 방법이 있습니까?

동영상 영역에 특수 효과, 클릭 유도 문안 또는 모든 종류의 오버레이 메시지/버튼을 사용해야합니다.

오버레이가 모든 비디오 재생 시간 동안 지속되는지 또는 비디오 끝에서만 표시되는지는 중요하지 않습니다.

누군가 나를 도울 수 있기를 바랍니다. 그리고 Google이 YouTube API를 구현하는 데 미쳐 버렸기 때문에 google이 더 나은 방법으로 문서를 다시 작성하기를 바랍니다.

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(); 
    } 
} 

답변

3

불행하게도, 그것은 가능하지 않으며 이제까지 지금까지 내가 말할 수있을 것입니다 :

내 소스 코드의 조각이다.

주석을 추가 할 수없는 것은 의도 한 동작입니다. 이 링크를 참조하십시오 : https://issuetracker.google.com/issues/35166657 - 상태 : (의도 된 동작을) 해결되지 않습니다

것은 분명히 가장 좋은 대안 인비 디오 프로그래밍입니다하지만 난이 비디오를 특정 할 수없는이, 당신의 목적에 적합 생각하지 않는다.

+0

정말 대단히 감사합니다! 나는 이미이 일을 포기했지만 누군가 내 질문에 대답 해 주신 것을 매우 기쁘게 생각합니다! 어쨌든 ... 인터넷에서 똑같은 것을 발견했습니다. 모든 종류의 클릭 유도 문안은 더 이상 사용되지 않습니다! 그래서 누군가가 똑같은 일을하려한다면 그것은 가능하지 않은 것 같습니다! –