1

我尝试使用 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。它工作正常。

4

0 回答 0