我这边利用NJS实现了IOS拍摄限时视频的功能,现在需要监听IOS拍摄完后的“确认使用”按钮,并且获取文件对象,进行上传,请问怎么获取文件对象
- 发布:2017-11-13 14:41
- 更新:2018-08-23 18:52
- 阅读:2847
m***@worldflying.cn (作者)
NJS拍摄IOS限时视频代码如下(修改了别人的):
var cameraVideo = plus.ios.newObject("UIImagePickerController");
cameraVideo.plusSetAttribute('delegate', cameraVideo);
cameraVideo.plusSetAttribute('sourceType', 1); //设置为摄像头0为相册
var iosArray = plus.ios.newObject('NSMutableArray');
plus.ios.invoke(iosArray, 'addObject:', 'public.movie');
cameraVideo.plusSetAttribute('mediaTypes', iosArray); //设置为录制视频
cameraVideo.plusSetAttribute('videoMaximumDuration', 10.01); //注意,这里的时间一定要保留2为小数,而且第二位小数一定要大于0,我这里进行了测试,用typeof输出变量的类型,发现typeof(10),typeof(10.0),typeof(10.00)输出的都是空,只有在第二位小数大于0的情况下,typeof输出的类型才是number,这样的值才能传入videoMaximumDuration中,这是个大坑
var UIApplicationClass = plus.ios.importClass("UIApplication");
var UIAppObj = UIApplicationClass.sharedApplication();
var del = plus.ios.invoke(UIAppObj, "delegate");
var appWindowObj = plus.ios.invoke(del, "window");
var appRootController = plus.ios.invoke(appWindowObj,"rootViewController");
plus.ios.invoke(appRootController,"presentViewController:animated:completion:",cameraVideo,"YES",null);
m***@worldflying.cn (作者)
var delegate = plus.ios.implements('UIImagePickerController',{
'imagePickerController:didFinishPickingMediaWithInfo:':function(picker,info){
plus.ios.invoke(appRootController,'dismissViewControllerAnimated:completion:','YES',function(){
var fm = plus.ios.newObject("NSFileManager");
var path = plus.io.PRIVATE_DOC+"/video_xx001.mov";
var resource = info.plusGetAttribute("UIImagePickerControllerMediaURL");
plus.ios.invoke("NSURL","fileURLWithPath:",path);
plus.ios.invoke(fm,"copyItemAtURL:toURL:error:",resource,path,null)
});
}
});
现在只求个大神来解决 info为空的问题,我就可以保住这份饭碗了
-
回复 typer:JSBObject
[LOG] : native_54
[LOG] : UIControlTargetAction
[LOG] : function (){var c,e,b=null;try{for(c=[],e=1;e<arguments.length;e++)c.push(d.warp(arguments[e]));b=a.bridge.execSync2(_Server,"plusSetAttribute",[this.UUID,arguments[0],c],null,!0),b=d.New(b,!0)}catch(f){throw f}return b}
[LOG] : function (b){var c=null;try{c=a.bridge.execSync2(_Server,"plusGetAttribute",[this.UUID,b],null,!0),c=a.ios.Tool.New(c,!0)}catch(d){throw d}return c}
[LOG] : function (){return a.android.importClass(this)}
[LOG] : function (b){var d,e,f,g,h,c=null;try{d="",e=[],f=0;for(g in b){if("string"!=typeof g)return;if(h=b[g],0==f){if(d=g,"undefined"==typeof h){f++;break}d+=":"}else d+=g+":";e.push(h),f++}if(0==f)return;e=window.plus.ios.__Tool.process(e),c=window.plus.bridge.execSync2(_Server,"exec",[this.UUID,d,e],null,!0),c=a.ios.__Tool.New(c,!0)}catch(i){throw i}return c}2018-08-24 14:48
m***@worldflying.cn (作者)
var NSDictionary = plus.ios.importClass("NSDictionary");
var ns = new NSDictionary();
var cameraVideo = plus.ios.newObject("UIImagePickerController");
cameraVideo.plusSetAttribute('delegate', cameraVideo);
cameraVideo.plusSetAttribute('sourceType', 1); //设置为摄像头0为相册
var iosArray = plus.ios.newObject('NSMutableArray');
plus.ios.invoke(iosArray, 'addObject:', 'public.movie');
cameraVideo.plusSetAttribute('mediaTypes', iosArray); //设置为录制视频
cameraVideo.plusSetAttribute('videoMaximumDuration', 5.01); //设置最大时长为10秒
plus.ios.implements("UIImagePickerControllerDelegate",{'imagePickerController:didFinishPickingMediaWithInfo:':function(cameraVideo,ns){
console.log(1);
}});
plus.ios.implements("UIImagePickerControllerDelegate",{"imagePickerControllerDidCancel:":function(){
console.log("cancel");
}})
var UIApplicationClass = plus.ios.importClass("UIApplication");
var UIAppObj = UIApplicationClass.sharedApplication();
var del = plus.ios.invoke(UIAppObj, "delegate");
var appWindowObj = plus.ios.invoke(del, "window");
var appRootController = plus.ios.invoke(appWindowObj,"rootViewController");
var result = plus.ios.invoke(appRootController,"presentViewController:animated:completion:",cameraVideo,"YES",null);
添加了连个代理,一个是成功选择了,一个是取消拍摄了,现在问题是不管是我取消还是选择了,代理都没有触发console.log,这是为什么,我哪里有错误?
m***@worldflying.cn (作者)
吐血了:最新代码如下,求告知,为嘛代理不生效
var NSDictionary = plus.ios.importClass("NSDictionary");
var ns = new NSDictionary();
var cameraVideo = plus.ios.newObject("UIImagePickerController");
cameraVideo.plusSetAttribute('sourceType', 1); //设置为摄像头0为相册
var iosArray = plus.ios.newObject('NSMutableArray');
plus.ios.invoke(iosArray, 'addObject:', 'public.movie');
cameraVideo.plusSetAttribute('mediaTypes', iosArray); //设置为录制视频
cameraVideo.plusSetAttribute('videoMaximumDuration', 5.01); //设置最大时长为10秒
var UIApplicationClass = plus.ios.importClass("UIApplication");
var UIAppObj = UIApplicationClass.sharedApplication();
var del = plus.ios.invoke(UIAppObj, "delegate");
var appWindowObj = plus.ios.invoke(del, "window");
var appRootController = plus.ios.invoke(appWindowObj,"rootViewController");
cameraVideo.plusSetAttribute('delegate', appRootController);
plus.ios.implements("UIImagePickerControllerDelegate",{
"imagePickerController:didFinishPickingMediaWithInfo:":function(cameraVideo,ns){
alert("success")
}
});
plus.ios.implements("UIImagePickerControllerDelegate",{
"imagePickerControllerDidCancel:":function(cameraVideo){
console.log("cancel")
}
})
plus.ios.invoke(appRootController,"presentViewController:animated:completion:",cameraVideo,"YES",function(){
console.log('start');
cameraVideo.plusSetAttribute('delegate',appRootController);//论坛说有可能delegate丢失了,在调起录像界面后,重新赋值一遍
});
m***@worldflying.cn (作者)
参考“元玉”小哥哥的代码,进行修改,结果,确认选择后回调卡死,取消按钮点击没反应
var NSDictionary = plus.ios.importClass("NSDictionary");
var ns = new NSDictionary();
var cameraVideo = plus.ios.newObject("UIImagePickerController");
var delegate = plus.ios.implements("UIImagePickerControllerDelegate",{
"imagePickerController:didFinishPickingMediaWithInfo:":function(picker,info){
console.log('info:'+arguments.length);
plus.ios.invoke(arguments[0],'dismissViewControllerAnimated:completion:','YES',null);
}
});
// var delegate = plus.ios.implements("UIImagePickerControllerDelegate",{
// "imagePickerControllerDidCancel:":function(picker){
// console.log('info:'+arguments.length);
// plus.ios.invoke(arguments[0],'dismissViewControllerAnimated:completion:','YES',null);
// }
// });
cameraVideo.plusSetAttribute('delegate',delegate);
cameraVideo.plusSetAttribute('sourceType', 1); //设置为摄像头0为相册
var iosArray = plus.ios.newObject('NSMutableArray');
plus.ios.invoke(iosArray, 'addObject:', 'public.movie');
cameraVideo.plusSetAttribute('mediaTypes', iosArray); //设置为录制视频
cameraVideo.plusSetAttribute('videoMaximumDuration', 5.01); //设置最大时长为10秒
var UIApplicationClass = plus.ios.importClass("UIApplication");
var UIAppObj = UIApplicationClass.sharedApplication();
var del = plus.ios.invoke(UIAppObj, "delegate");
var appWindowObj = plus.ios.invoke(del, "window");
var appRootController = plus.ios.invoke(appWindowObj,"rootViewController");
plus.ios.invoke(appRootController,"presentViewController:animated:completion:",cameraVideo,"YES",function(){
console.log('start');
});
m***@worldflying.cn (作者)
implements("UIImagePickerController",{
"imagePickerController:didFinishPickingMediaWithInfo:":function(picker,info){
console.log(info)
})
LOG: 空
typer
给力,兄弟,成功解决了录制时长的问题
2018-08-15 15:31
jspeng
@jarodxie@foxmail.com:请问怎么拿到他的视频路径?
2018-08-17 10:50
typer
回复 jspeng:我的代理都还没有调起来。。。你调起来了吗
2018-08-23 16:57
typer
cameraVideo.plusSetAttribute('delegate', cameraVideo); 应该是cameraVideo.plusSetAttribute('delegate', delegate);
2018-08-23 17:41