---
name: "processPetForegroundMediaByTemplate"
mode: "kit"
versionRequirements:
  - { name: "AIKit", version: "1.4.3" }
  - { name: "@ray-js/ray", version: "1.7.27" }
platform:
  - "iOS"
  - "Android"
async: true
title: "processPetForegroundMediaByTemplate"
---

## processPetForegroundMediaByTemplate

> [VERSION] AIKit >= 1.4.3 | @ray-js/ray >= 1.7.27

> [PLATFORM] iOS, Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Compose pet foreground media based on a template

### Parameters

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `templateObject` | `ForegroundMediaTemplateObject` | Yes | - | `1.4.3` | Template object |
| `mediaSource` | `string` | Yes | - | `1.4.3` | Input media data source |
| `outputConfig` | `OutputConfig` | No | - | `1.4.3` | Output configuration |
| `extendParam` | `Record<string, any>` | No | - | `1.4.3` | Extended parameters |
| `complete` | `() => void` | No | - | - | Completion callback (executed on both success and failure) |
| `success` | `(params: Object) => void` ↓see below | No | - | - | Callback on successful API call |
| `fail` | `(params: Object) => void` ↓see below | No | - | - | Failure callback |

#### success callback parameters

| Property | Type | Since | Description |
| --- | --- | --- | --- |
| `outputPath` | `string` | `1.4.3` | Path of the output foreground media |
| `extData` | `Record<string, any>` | `1.4.3` | Extension data |

#### fail callback parameters

| Property | Type | Description |
| --- | --- | --- |
| `errorMsg` | `string` | Error message |
| `errorCode` | `string \| number` | Error code |
| `innerError` | `Object` | Error extension |

##### fail(params).innerError properties

| Property | Type | Description |
| --- | --- | --- |
| `errorCode` | `string \| number` | Error extension code |
| `errorMsg` | `string` | Error extension message |


### Referenced Types

##### `interface` ForegroundMediaTemplateObject

| Property | Type | Required | Since | Description |
| --- | --- | --- | --- | --- |
| `type` | `string` | Yes | `1.3.2` | Template type, sourced from the cloud |
| `effect` | `ForegroundMediaTemplateEffectObject` | Yes | `1.3.2` | Template effect object |
| `extendParam` | `Record<string, any>` | No | `1.3.2` | Extended parameters |

##### `interface` OutputConfig

| Property | Type | Required | Since | Description |
| --- | --- | --- | --- | --- |
| `path` | `string` | No | `1.3.2` | Path of the output foreground media |
| `name` | `string` | No | `1.3.2` | Filename of the output foreground media |
| `min_duration` | `number` | No | `1.3.2` | Minimum duration of the output foreground media, in seconds |
| `outputType` | `string` | No | `1.4.3` | Output type; supports image, audio, video; defaults to image |
| `extendParam` | `Record<string, any>` | No | `1.3.2` | Extended parameters |

##### `interface` ForegroundMediaTemplateEffectObject

| Property | Type | Required | Since | Description |
| --- | --- | --- | --- | --- |
| `code` | `string` | Yes | `1.3.2` | Effect code |
| `name` | `string` | Yes | `1.3.2` | Effect name |
| `ouputDuration` | `number` | Yes | `1.3.2` | Deprecated; use outputDuration |
| `outputDuration` | `number` | Yes | `1.4.3` | Effect output duration, in seconds |
| `outputType` | `string` | No | `1.4.3` | Effect output type; supports image, audio, video; defaults to image |
| `image` | `string` | Yes | `1.3.2` | Effect preview image URL |
| `resource` | `string` | Yes | `1.3.2` | Effect resource URL |
| `extendParam` | `Record<string, any>` | No | `1.3.2` | Extended parameters |


### Examples

```tsx
import { ai } from '@ray-js/ray'

ai.processPetForegroundMediaByTemplate({
  templateObject: {
    type: "xx",
    effect: {
      code: "xx",
      name: "xx",
      ouputDuration: 3000,
      outputDuration: 3000,
      image: "xx",
      resource: "xx",
    },
  },
  mediaSource: "xx",
  outputConfig: {},
  extendParam: {},
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});
```
