【发布时间】:2013-12-04 23:25:15
【问题描述】:
我正在构建一个中继服务,它将视频从外部服务器传递到 YouTube。目前我的代码正在按预期工作,但我需要避免提前在本地保存文件以使用 MediaFileSource 上传到 YouTube。有没有办法传递 InputStream 而不是文件并使用 MediaStreamSource 来允许管道?
https://developers.google.com/gdata/javadoc/com/google/gdata/data/media/MediaStreamSource
这样我就可以像这样直接传输文件
YouTubeService youTubeService = new YouTubeService("My-Service", developerKey);
youTubeService.setUserCredentials(user, password);
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent("Song Title");
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Category"));
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("Test");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent("Song Description");
mg.setPrivate(false);
MediaStreamSource ms = new MediaFileSource(new URL("http://www.somewebsite.com/video.mp4").openStream(), "video/mp4");
newEntry.setMediaStream(ms);
String uploadUrl = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
VideoEntry createdEntry = youTubeService.insert(new URL(uploadUrl), newEntry);
return createdEntry.getHtmlLink().getHref();
【问题讨论】:
标签: java youtube-api