From 7c0ea7c452a8b52f5d2a76cb7377891270a4abfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Rodr=C3=ADguez?= Date: Sat, 7 Oct 2023 12:48:22 +0200 Subject: [PATCH] Add Example usago to Readme --- README.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 01b84e0..bdf2cba 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,14 @@ npx cap sync ### or for Capacitor 4.x ```bash -pm install @whiteguru/capacitor-plugin-video-editor@^4.0.4 +npm install @whiteguru/capacitor-plugin-video-editor@^4.0.4 npx cap sync ``` ### or for Capacitor 3.x ```bash -pm install @whiteguru/capacitor-plugin-video-editor@^3.0.1 +npm install @whiteguru/capacitor-plugin-video-editor@^3.0.1 npx cap sync ``` @@ -43,6 +43,58 @@ The storage permissions are for reading video files. Read about [Setting Permissions](https://capacitorjs.com/docs/android/configuration#setting-permissions) in the [Android Guide](https://capacitorjs.com/docs/android) for more information on setting Android permissions. +## Example + +```typescript +import { VideoEditor, MediaFileResult } from '@whiteguru/capacitor-plugin-video-editor'; + +const sourceVideoPath = + 'file:///var/mobile/Containers/Data/...../sourceVideo.mp4'; + +// Transcode with progress +const progressListener = await VideoEditor.addListener( + 'transcodeProgress', + (info) => console.log('info', info) +); + +VideoEditor.edit({ + path: sourceVideoPath, + transcode: { + width: 720, + height: 480, + keepAspectRatio: true, + }, + trim: { + startsAt: 3 * 1000, // from 00:03 + endsAt: 10 * 1000, // to 00:10 + }, +}).then( + (mediaFileResult: MediaFileResult) => { + progressListener.remove(); + + console.log('mediaPath', mediaFileResult.file.path); + }, + (error) => { + console.error('error', error); + } +); + +// Thumbnail +VideoEditor.thumbnail({ + path: sourceVideoPath, + width: 150, + height: 150, + at: 4 * 1000, // at 00:04 +}).then( + (thumbMediaFileResult: MediaFileResult) => { + console.log('thumbPath', thumbMediaFileResult.file.path); + }, + (error) => { + console.error('error', error); + } +); +``` + ## API