fastworker399
fastworker399

Reputation: 423

Ionic How to get thumbnail from local video file?

I captured and download video files using Media capture and cordova transfer plugins. I have no idea how to get thumbnails from these video files. Please help me. Thanks.

Upvotes: 0

Views: 5634

Answers (2)

Raj Gond
Raj Gond

Reputation: 11

createThumbnail(videodata){
    let thumbnailoption : CreateThumbnailOptions = {
        fileUri:videodata,
        quality:100,
        atTime:1,
        outputFileName: 'thumbnailImage',
    }
    this.videoEditor.createThumbnail(thumbnailoption).then((thumbnailPath)=>{
        console.log("Thumbnail Responce =>",thumbnailPath)
        this.thumbnail = thumbnailPath;

    }).catch((err)=>{
      console.log("Thumbnail Responce Error=>",err)

    })
  }



  <video autoplay (click)="videovideoPlaypathPlay(videofullpath)" [poster]="thumbnail" preload="auto">   
                     <source src="videodata ? videodata : {{fileServiceUrl}}{{videoKey}}.mp4" type="video/mp4"  class="partyPhoto">
          </video>

it was not works ..!!

Upvotes: 1

fastworker399
fastworker399

Reputation: 423

   import { VideoEditor,CreateThumbnailOptions } from '@ionic-native/video-editor';
  CreateVideo()
  {
    var nItem = localStorage.getItem('videoNum');
    var numstr = 0;
    if(nItem == null){
      numstr = 1;
    }
    else{
      var numstr = parseInt(nItem,10);
      numstr = numstr + 1;
    }

    let videooption:CaptureVideoOptions = {limit:1};

    this.mediaCapture.captureVideo().then((videoData:Array<MediaFile>)=>{

    let filedir = this.file.dataDirectory ;

    var path = videoData[0].fullPath.replace('/private','file://');
    var ind = (path.lastIndexOf('/')+1);
    var orgFilename = path.substring(ind);
    var orgFilePath = path.substring(0,ind);

    console.log("videopath", path);
  //SAVE FILE
    this.file.copyFile(orgFilePath, orgFilename, filedir + 'recordvideo','sample'+numstr+'.mov').then(()=>{
    var option:CreateThumbnailOptions = {fileUri:filedir+'recordvideo/sample'+numstr+'.mov',width:160, height:206, atTime:1, outputFileName: 'sample' + numstr, quality:50 };
    this.videoEditor.createThumbnail(option).then(result=>{
        //result-path of thumbnail
       localStorage.setItem('videoNum',numstr.toString());          
    }).catch(e=>{
     // alert('fail video editor');
    });
  });

});}

This is my answer.

Upvotes: 2

Related Questions