2017-10-12 17 views
6

मेरे कोड को उत्पन्न करने के लिए मैंने gitHub पर Google से रखे नमूने को संशोधित किया।जब मैं जावा यूट्यूब एपीआई का उपयोग कर इसे अपलोड कर रहा हूं तो वीडियो में एनोटेशन या 'एंड स्क्रीन' जोड़ना संभव है?

सभी ठीक हो जाते हैं और वीडियो अपलोड में कोई समस्या नहीं है लेकिन अब मुझे अपने वीडियो में कुछ एनोटेशन या 'एंड स्क्रीन' डालना होगा क्योंकि मुझे अपने 'वीडियो पूर्वावलोकन' को देखने के बाद उपयोगकर्ताओं को अपनी साइट पर रीडायरेक्ट करने की आवश्यकता है। एक jsp पेज से

1) उपयोगकर्ता आवेषण शीर्षक और विवरण:

तो, कार्यप्रवाह कुछ इस तरह है।

2) जब वह बटन पर क्लिक करता है तो सॉफ़्टवेयर मेरे डीबी में संग्रहीत उपयोगकर्ता के प्रमाण-पत्र लेता है और फिर नीचे दिए गए तरीके से सभी पैरामीटर पास करता है।

3) कक्षा वीडियो को YouTube पर अपलोड करती है।

अब मेरा प्रश्न है: अपलोड किए गए वीडियो के मेरे लिंक 'संलग्न' करने का एक आसान तरीका है?

मुझे वीडियो क्षेत्र पर एनोटेशन, कॉल-टू-एक्शन या किसी भी तरह का ओवरले संदेश/बटन जैसे कुछ उपयोग करना चाहिए।

इससे कोई फर्क नहीं पड़ता कि ओवरले सभी वीडियो अवधि के लिए बनी रहती है या यह केवल वीडियो के अंत में दिखाई देती है।

मुझे उम्मीद है कि कोई मेरी मदद कर सकता है! और मुझे आशा है कि 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

आपको बहुत मच धन्यवाद! मैंने पहले से ही इस काम को छोड़ दिया है, लेकिन मुझे बहुत खुशी है कि किसी ने मेरे प्रश्न का उत्तर दिया है! वैसे भी ... मुझे इंटरनेट पर एक ही चीज़ मिली, सभी प्रकार के कॉल-टू-एक्शन को बहिष्कृत कर दिया गया है! तो अगर कोई एक ही काम करने की कोशिश कर रहा है, तो ऐसा संभव नहीं लगता है! –

संबंधित मुद्दे

 संबंधित मुद्दे