我正在开发一个显示器,把一张卡片中的录像带上你管,然后把你管录像带回。 然而,我未能成功这样做。
我以行动努力:
public void onUploadClick(View v) {
Intent uploadIntent = new Intent(Intent.ACTION_SEND);
// In a real app, video would be captured from camera.
File f = new File("/sdcard/test.mov");
uploadIntent.setDataAndType(Uri.fromFile(f), "video/quicktime");
startActivity(Intent.createChooser(uploadIntent, "Upload"));
}
But, oddly, with this implementation I do not have Youtube as an option for the upload. I have Bluetooth, Mail, Dropbox, Facebook, Flickr, Gmail and Handcent. But not Youtube. Any thoughts on this? Besides, is it possible using this method to have the url of the youtube video after uploaded? How?
I have also tried using Youtube API for Java, and again no success. I added all the libraries needed (gdata-client-1.0.jar, gdata-media-1.0.jar and gdata-youtube-2.0,jar). However, when I run it I get a NoClassDefFoundError for com.google.gdata.client.youtube.YouTubeService, despite having the right libs and imports. Here is the code I am using:
YouTubeService service = new YouTubeService(clientID, developer_key);
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent("My Test Movie");
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, "Autos"));
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("cars");
mg.getKeywords().addKeyword("funny");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent("My description");
mg.setPrivate(false);
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "mydevtag"));
mg.addCategory(new MediaCategory(YouTubeNamespace.DEVELOPER_TAG_SCHEME, "anotherdevtag"));
newEntry.setGeoCoordinates(new GeoRssWhere(37.0,-122.0));
// alternatively, one could specify just a descriptive string
// newEntry.setLocation("Mountain View, CA");
MediaFileSource ms = new MediaFileSource(new File("file.mov"), "video/quicktime");
newEntry.setMediaSource(ms);
String uploadUrl =
"http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";
VideoEntry createdEntry = service.insert(new URL(uploadUrl), newEntry);
To sum up, my questions are: - What am I doing wrong in both approaches? - Regarding my simple objective of uploading a video to youtube and getting its youtube link after, which method do you recommend? Even if it s neither of those above.
谢谢。
---- Update 04/10 ----
- After trying with a differente phone I found out that Youtube not showing up as choice to upload the video is my phone s problem (probably due to the ROM). However, even if it does work using intents is not the way to go because I cannot get the URL back and that is essential.
- After some research it seems that the second method is not possible. The Youtube API for Java does not work in Android.
That being said, I am looking for suggestions on how to upload a video to Youtube in Android. What I really want is to choose a video file, upload it to Youtube and get the youtube URL. Preferably without any interference from the user, who only chooses the file and then the uploading and URL retrieving runs "in the background". Any suggestions? What is the easiest and fastest way to achieve this?
感谢。