如何通过单击在ionic2中打开的相机上的后退按钮导航到页面

时间:2018-09-07 11:44:58

标签: ionic-framework ionic2 camera back-button

我有一个主页,并在ionViewWillEnter()中添加了相机代码。这样,当HomePage触发时,它会首先打开Camera

我想自定义后退按钮的行为,即当我按下后退按钮时,打开相机后,它应该导航到SecondPage,默认情况下,它正在导航到HomePage。

ionViewWillEnter() {
   this.captureVideo();
 }


 captureVideo() {
    platform.registerBackButtonAction(() => {
      this.navCtrl.push(SecondPage)
       });
    let options: CaptureVideoOptions = { limit: 1 };
    this.mediaCapture.captureVideo(options)
     .then((videodata: MediaFile[]) => {
      var i, path, len;
     for (i = 0, len = videodata.length; i < len; i += 1) {
      path = videodata[i].fullPath;

      }

      this.flag_play = false;
      this.flag_upload = false;


     this.file.resolveLocalFilesystemUrl(path).then((newUrl) => {
     alert(JSON.stringify(newUrl))
     let dirPath = newUrl.nativeURL;
     let dirPathSegments = dirPath.split('/')
     dirPathSegments.pop()
     dirPath = dirPathSegments.join('/')
     this.file.readAsArrayBuffer(dirPath, newUrl.name).then(async (buffer) 
        => {
        await this.upload(buffer, newUrl.name);

          })

        })
        })
     .then(() => {


       var videoFileName = 'video-name-here'; 

       this.videoEditor.createThumbnail(

        {
         fileUri:'abc',// this.videoId,
         outputFileName: videoFileName,
         atTime: 2,
         width: 320,
         height: 480,
         quality: 100
        }
       ).then(result => {



     this.result = result;
     this.base64.encodeFile(result).then((base64File) => {
      this.base64Thumbnail = base64File.replace("*;charset=utf-8", "jpg")

       }, err => {

       alert("Unable to create thumbnail")
      })

       })
       })

       }

1 个答案:

答案 0 :(得分:0)

硬件后退按钮用作取消的默认行为...因此要对其进行自定义,会将您的特定代码置于错误中...

  takePicture(){
    this.camera.getPicture({
       destinationType: this.camera.DestinationType.DATA_URL,
      targetWidth: 1000,
      targetHeight: 1000
     }).then((imageData) => {
  // imageData is a base64 encoded string
       this.base64Image = "data:image/jpeg;base64," + imageData;
    }, (err) => {
   this.navCtrl.pop();

   });
  }
  }