我正在尝试从我的应用上传视频到youtube。我找到了许多引用来做这个,但所有那些首先在设备上打开youtube应用程序,然后上传视频表单的应用程序,我想直接上传而不打开youtube app.But引用显示为webview打开通过传递youtube.so的URL如果任何人都有这个想法,请帮助我们。
任何简单的示例代码,因为项目的结束时间。
答案 0 :(得分:1)
YouTube Direct Lite for Android显示了最佳方式。
答案 1 :(得分:0)
以下是帮助我的代码,请尝试它对您有用
public class MainActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
Intent intent;
private static final int SELECT_VIDEO_REQUEST = 1000;
// static private final String DEVELOPER_KEY = " ";
static private final String DEVELOPER_KEY ="YOUR API KEY";
static private final String VIDEO_ID = "qVIwHGI2e1U";
//static private final String VIDEO_ID ="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(DEVELOPER_KEY, this);
Button click = (Button) findViewById(R.id.button2);
click.setOnClickListener(onClickListener);
}
private OnClickListener onClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
intent = new Intent(android.content.Intent.ACTION_PICK);
intent.setType( "video/*");
startActivityForResult(intent,SELECT_VIDEO_REQUEST);
}};
@Override
public void onInitializationFailure(Provider provider, YouTubeInitializationResult error) {
Toast.makeText(this, "Oh no! "+error.toString(), Toast.LENGTH_LONG).show();
}
@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
player.loadVideo("VIDEO_ID");
//player.loadVideo("");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent returnedIntent) {
if (resultCode == RESULT_OK) {
switch (requestCode) {
case SELECT_VIDEO_REQUEST:
Intent intent = YouTubeIntents.createUploadIntent(this, returnedIntent.getData());
startActivity(intent);
break;
}
}
super.onActivityResult(requestCode, resultCode, returnedIntent);
}
public static String getVideoId() {
return VIDEO_ID;
}}