flutter 端
const platform = MethodChannel('samples.flutter.dev/battery');
Future _upLoadVideo(String path) async {
OSS oss= Global.mediaOss;
String videoid = "1";
try {
final String result = await platform.invokeMethod('upLoadVideo',{"path":path,"accessKeyId":oss.accessKeyId,
"accessKeySecret":oss.accessKeySecret,"securityToken":oss.securityToken,"expiration":oss.expiration.toString()});
print("result:" + result);
return result;
} on PlatformException catch (e) {
print("result:" + e.message.toString());
}
print("result:" + videoid);
return videoid;
}
android端
private static final String CHANNEL = "samples.flutter.dev/battery";
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
super.configureFlutterEngine(flutterEngine);
new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
.setMethodCallHandler(
(call, result) -> {
// Note: this method is invoked on the main thread.
if (call.method.equals("getBatteryLevel")) {
result.success(100);
// if ((String) call.argument("inputText") != null) {
// result.success(getJavaText((String) call.argument("inputText"), (int) call.argument("anotherArgument")));
// } else {
// result.error("UNAVAILABLE", "This Method is not available now.", null);
// }
} else if (call.method.equals("upLoadVideo")) {
//初始化短视频上传对象
// accessKeyId = (String) call.argument("accessKeyId");
// accessKeySecret = (String) call.argument("accessKeySecret");
// securityToken = (String) call.argument("securityToken");
// expriedTime = (String) call.argument("expiration");
String path = (String) call.argument("path");
// Log.e("TAG", path + "----" + this.accessKeyId + "--" +this.accessKeySecret+"----"+this.securityToken+"----"+this.expriedTime);
// uploadVideo(path.replace("/data/user/0/","/data/data/"), result);
if (path != null) {
uploadVideo(path.replace("/data/user/0/","/data/data/"), result);
Log.e("TAG", path + "----" + this.accessKeyId + "--" +this.accessKeySecret+"----"+this.securityToken+"----"+this.expriedTime);
} else {
result.error("UNAVAILABLE", "视频路径错误,请重试", null);
}
} else {
result.notImplemented();
}
}
);
}