首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用YouTube接口和MediaStreamSource上传视频到YouTube

如何使用YouTube接口和MediaStreamSource上传视频到YouTube
EN

Stack Overflow用户
提问于 2013-12-05 07:25:15
回答 1查看 255关注 0票数 0

我正在构建一个中继服务,它将视频从外部服务器传递到YouTube。目前,我的代码运行正常,但我需要避免提前将文件保存在本地,以便使用MediaFileSource将文件上传到YouTube。有没有一种方法可以传递InputStream而不是文件,并使用MediaStreamSource来允许管道?

https://developers.google.com/gdata/javadoc/com/google/gdata/data/media/MediaStreamSource

这样,我就可以像这样直接通过管道传输文件

代码语言:javascript
复制
 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();
EN

回答 1

Stack Overflow用户

发布于 2014-01-23 19:50:06

我遇到了一个错误,不得不将我的代码编辑为:

代码语言:javascript
复制
String title = "Test Video";
youTubeService.getRequestFactory().setHeader("Slug", title);

我想我应该提一下因为我没在你的片断里看到这个。但是上传的时间太长了。你的上传有什么进展吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20388267

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档