我尝试使用Android将视频从SD卡上传到youtube。我正在使用Google API进行YouTube上传。视频上传成功,但旋转180度。我使用以下代码 -
YouTubeService service = new YouTubeService(Strings.YOUTUBE_CLIENT_ID,Strings.YOUTUBE_DEV_ID);
try{
service.setUserCredentials("abc123@gmail.com", "ag23sjafaar");
} catch (AuthenticationException ex){
Log.e("AuthenticationError",":"+ex.getMessage());
return;
}
File videoFile = new File(Strings.VIDEO_PATH);
if(!videoFile.exists()){
Log.e("FileUploadErr","FileNotFound");
return;
}
String mimeType = "video/*";
String videoTitle = name;
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME,"Travel"));
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent(videoTitle);
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("Travel");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent(videoTitle);
MediaFileSource ms = new MediaFileSource(videoFile,mimeType);
newEntry.setMediaSource(ms);
try{
VideoEntry createdEntry = service.insert(new URL(Strings.YOUTUBE_VIDEO_UPLOAD_URL), newEntry);
} catch(ServiceException se){
Log.e("UploadVideo",":" + se.getMessage());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
更新 如果我从SD卡浏览视频并使用模拟器在youtube上上传。它工作正常。