我可以下载视频和图像,但是无法播放(不支持文件格式,或者文件损坏了吗?)。
我被困从Google云端硬盘中获取可播放的视频。
任何帮助都是可观的。
-我的按钮onclick旨在使用Google驱动器。
open.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onClickOpenFile(v);
}
});
public void onClickOpenFile(View view) {
fileOperation = false;
// create new contents resource
Drive.DriveApi.newDriveContents(mGoogleApiClient)
.setResultCallback(driveContentsCallback);
}
打开Google云端硬盘的文件夹和文件列表
public void OpenFileFromGoogleDrive() {
IntentSender intentSender = Drive.DriveApi
.newOpenFileActivityBuilder()
.setMimeType(new String[]{"image/jpeg", "image/png", "video/mp4"
, "application/vnd.openxmlformats-officedocument.wordprocessingml.document"})
.build(mGoogleApiClient);
try {
startIntentSenderForResult(
intentSender, REQUEST_CODE_OPENER, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG, "Unable to send intent", e);
}
}
final ResultCallback<DriveApi.DriveContentsResult> driveContentsCallback =
new ResultCallback<DriveApi.DriveContentsResult>() {
@Override
public void onResult(DriveApi.DriveContentsResult result) {
if (result.getStatus().isSuccess()) {
OpenFileFromGoogleDrive();
}
}
};
@Override
protected void onActivityResult(final int requestCode,
final int resultCode, final Intent data) {
switch (requestCode) {
case REQUEST_CODE_OPENER:
if (resultCode == RESULT_OK) {
video_url = "https://drive.google.com/open?id=" + mFileId.getResourceId();
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(video_url));
startActivity(i);
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
break;
}
}