有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

youtube如何使用Java+Google数据API测量上传比特率

我正在编写一个Java客户端应用程序,它使用Google Data API将内容上传到youtube。我想知道我将如何使用谷歌数据API库跟踪上传的进度,我只是称之为服务。insert可插入一个新视频,该视频会一直阻止,直到完成

是否有其他人想出了一个解决方案来监控上传的状态,并在发送时计算字节数

谢谢你的建议

链接:

http://code.google.com/apis/youtube/2.0/developers_guide_java.html#Direct_Upload


共 (1) 个答案

  1. # 1 楼答案

    扩展com。谷歌。格达塔。数据媒体MediaSource writeTo()包含字节读取计数器:

         public static void writeTo(MediaSource source, OutputStream outputStream)
            throws IOException {
    
          InputStream sourceStream = source.getInputStream();
          BufferedOutputStream bos = new BufferedOutputStream(outputStream);
          BufferedInputStream bis = new BufferedInputStream(sourceStream);
          long byteCounter = 0L; 
    
          try {
            byte [] buf = new byte[2048]; // Transfer in 2k chunks
            int bytesRead = 0;
            while ((bytesRead = bis.read(buf, 0, buf.length)) >= 0) {
              // byte counter
              byteCounter += bytesRead;
              bos.write(buf, 0, bytesRead); 
            }
            bos.flush();
          } finally {
            bis.close();
          }
        }
      }