簡體   English   中英

Media Capture本機插件Ionic 3

[英]Media Capture Native Plugin Ionic 3

我正在開發一個ionic 3應用程序,我希望用戶可以在其中捕獲圖片和視頻。 因此,我使用了媒體捕獲插件,一旦捕獲圖像或視頻,我就會得到MediaFile[]承諾。 現在,當我嘗試使用[src] = mediaFile['0'].fullPathion-img標簽中將該圖像顯示為預覽時。 它沒有顯示圖像。

請告訴我我的方法是否錯誤,那我該怎么辦。

這是捕獲部分:

this.mediaCapture.captureImage()
  .then(

    (data: MediaFile[]) => {
         this.navCtrl.push('NewPostPage', {
         mediaFile : data
         })
    },
    (err: CaptureError) => console.error(err)
  );

這是newpostpage的html:

<ion-content padding>

  <ion-img [src] = 'image'></ion-img>

</ion-content>

這是newpostpage的.ts文件:

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { MediaFile } from '@ionic-native/media-capture';

/**
 * Generated class for the NewPostPage page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-new-post',
  templateUrl: 'new-post.html',
})
export class NewPostPage {

  constructor(public navCtrl: NavController, public navParams: NavParams) {
  }

  mediaFile: MediaFile[] = this.navParams.get('mediaFile');
  image: string = this.mediaFile['0'].fullPath;


  ionViewDidLoad() {
    console.log('ionViewDidLoad NewPostPage');
    console.log(this.image);    
  }

}

嘿,不知道您是否仍然遇到此問題。

解決此問題的方法是在控制台中打印文件路徑,然后嘗試刪除其中的不同部分並查看有效的方法。

具體來說,有效的方法是刪除"file:"前綴,如下所示:

self.media.captureVideo().then((data: MediaFile[]) => {
                let file = data.pop();
                let path = file.fullPath.replace('file:', '');
                resolve(path);
            }, err => {
                console.dir(err);
                reject(err);
            }); 

然后,我可以使用該路徑來傳輸/播放文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM