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

问题描述 投票:0回答:1

我有一个HomePage和ionViewWillEnter()我添加了相机代码。因此,当HomePage获得触发时,它首先打开相机

我想自定义后退按钮行为,当我按下后退按钮时,打开相机后它应导航到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")
      })

       })
       })

       }
ionic-framework ionic2 camera back-button
1个回答
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();

   });
  }
  }
© www.soinside.com 2019 - 2024. All rights reserved.