學(xué)習(xí)ionic有一段時(shí)間的,之前一直是在別人的簡(jiǎn)書博客下天天向上,最近做視頻的時(shí)候發(fā)現(xiàn)基本的視頻操作的資料很少,自己研究了之后來(lái)分享一波,希望可以幫助到各位小伙伴。
ps:我的開發(fā)環(huán)境:mac10.12,ionic 3.0.4
1.視頻錄制
1.視頻錄制的插件:點(diǎn)擊點(diǎn)擊Up Up
2.插件的集成:
$ ionic cordova plugin add cordova-plugin-video-capture-plus
$ npm install --save @ionic-native/video-capture-plus
3.記得在加哦
4.插件的使用
```
didTakeVideo() {
alert('beginVideo');
constoptions: VideoCapturePlusOptions = {
limit:1,
highquality:true,
portraitOverlay:'assets/img/camera/overlay/portrait.png',
landscapeOverlay:'assets/img/camera/overlay/landscape.png'
}
this.videoCapturePlus.captureVideo(options).then((mediafile) => {
this.videoData= mediafile[0].fullPath;
alert(this.videoData);
this.load.dismiss()
}, (err) => {
alert('videoFaile');
console.log('Something went wrong');
// Handle error
});
}
```
2.圖庫(kù)的視頻選擇
1.視頻選擇需要用到的插件:這里這里
2.插件的集成
$ ionic cordova plugin add cordova-plugin-camera
$ npm install --save @ionic-native/camera
3.同樣不要不要忘記添加哦
4.插件的使用
```
getPicture(options: CameraOptions = {}): Promise {
letops: CameraOptions =Object.assign({
mediaType:this.camera.MediaType.VIDEO,
sourceType:this.camera.PictureSourceType.SAVEDPHOTOALBUM,//圖片來(lái)源,CAMERA:拍照,PHOTOLIBRARY:相冊(cè)
destinationType:this.camera.DestinationType.FILE_URI,//默認(rèn)返回base64字符串,DATA_URL:base64? FILE_URI:圖片路徑
}, options);
return newPromise((resolve) => {
this.camera.getPicture(ops).then((videoURL :string) => {
alert('好的好的可以了');
resolve(videoURL);
alert(videoURL);
}, (err) => {
alert('沒有權(quán)限,請(qǐng)?jiān)谠O(shè)置中開啟權(quán)限');
});
});
};
getVideoByPhotoLibrary(options: CameraOptions = {}) {
this.getPicture(Object.assign({
sourceType:this.camera.PictureSourceType.SAVEDPHOTOALBUM,
destinationType:this.camera.DestinationType.FILE_URI//DATA_URL: 0 base64字符串, FILE_URI: 1圖片路徑
}, options)).then((vedioURL :string) => {
alert('shoudaoURL');
this.videoData= vedioURL;
alert(this.videoData);
this.load.dismiss()
}).catch(err => {
alert('NOURL');
});
};
```
至此我簡(jiǎn)單的分享了ionic視頻基本的錄制和選取,播放的話呢直接用H5的video就可以了,實(shí)現(xiàn)以后我發(fā)現(xiàn)有一點(diǎn)小小的問題是視頻錄制或者選取成功以后,vedio的播放按鈕會(huì)變成可播放,但是視頻的背景圖還沒有現(xiàn)實(shí)在播放器中,點(diǎn)擊播放按鈕后可以正常播放,再關(guān)閉播放就有視頻的背景圖了,有會(huì)解決這個(gè)問題的小伙伴,歡迎指教哦。