# Play videos on command

**URL:** https://forum.convai.com/t/play-videos-on-command/4375
**Category:** Unity SDK
**Tags:** question, narrative-design, unity
**Created:** [June 26, 2025, 8:51am UTC](https://forum.convai.com/t/play-videos-on-command/4375 "2025-06-26T08:51:51Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Luca\_Trianti](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/luca_trianti/32/4775_2.png) [@Luca\_Trianti](https://forum.convai.com/u/Luca_Trianti)
#### Post date: [June 26, 2025, 8:51am UTC](https://forum.convai.com/t/play-videos-on-command/4375/1 "2025-06-26T08:51:51Z")

</div>

Is there a way to make the NPC “show” you a video on a media player on user request?

E.G:

“Can you show me a video of the last show?”

“Sure”

_Media player pops up with the video_

Keep in mind that the NPC will stand still and never moves.

---

<div class="post-metadata">

### Author: ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)
#### Post date: [June 26, 2025, 9:06am UTC](https://forum.convai.com/t/play-videos-on-command/4375/2 "2025-06-26T09:06:05Z")

</div>

Hello @Luca_Trianti,

**Welcome to the Convai Developer Forum!**

You can use our Action Feature.

> **[Adding Actions to your Character | Convai Documentation](https://docs.convai.com/api-docs/plugins-and-integrations/unity-plugin/adding-actions-to-your-character)**
>
> Follow these instructions to enable actions for your Convai-powered characters.

---

<div class="post-metadata">

### Author: ![Luca\_Trianti](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/luca_trianti/32/4775_2.png) [@Luca\_Trianti](https://forum.convai.com/u/Luca_Trianti)
#### Post date: [June 27, 2025, 7:49am UTC](https://forum.convai.com/t/play-videos-on-command/4375/3 "2025-06-27T07:49:34Z")

</div>

Thanks! But is there a way to know what video to play based on user request?

---

<div class="post-metadata">

### Author: ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)
#### Post date: [June 27, 2025, 11:35am UTC](https://forum.convai.com/t/play-videos-on-command/4375/4 "2025-06-27T11:35:25Z")

</div>

This depends on how you’ve implemented your PlayVideo action. You’ll need to determine which video to play based on your implementation.

Alternatively, you can use our Narrative Design feature. You can configure sections corresponding to each video, and based on the user input, the relevant section will be triggered,where you can initiate the video accordingly.

---

<div class="post-metadata">

### Author: ![Luca\_Trianti](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/luca_trianti/32/4775_2.png) [@Luca\_Trianti](https://forum.convai.com/u/Luca_Trianti)
#### Post date: [June 30, 2025, 9:40am UTC](https://forum.convai.com/t/play-videos-on-command/4375/5 "2025-06-30T09:40:03Z")

</div>

Thanks! I actually solved this issue with the narrative design and some scripting (by detecting with API calls when the NPC replied in specific ways). Thanks for your help!

---

<div class="post-metadata">

### Author: ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)
#### Post date: [June 30, 2025, 9:46am UTC](https://forum.convai.com/t/play-videos-on-command/4375/6 "2025-06-30T09:46:58Z")

</div>

@Luca_Trianti Awesome!

---

<div class="post-metadata">

### Author: ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)
#### Post date: [June 30, 2025, 9:27pm UTC](https://forum.convai.com/t/play-videos-on-command/4375/7 "2025-06-30T21:27:00Z")

</div>

@Luca_Trianti Do you want to share your solution so that other users can use it too?

---

<div class="post-metadata">

### Author: ![Jeasy\_Sehgal](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/jeasy_sehgal/32/2881_2.png) [@Jeasy\_Sehgal](https://forum.convai.com/u/Jeasy_Sehgal)
#### Post date: [July 1, 2025, 4:34am UTC](https://forum.convai.com/t/play-videos-on-command/4375/8 "2025-07-01T04:34:00Z")

</div>

@Luca_Trianti Is it possible for you to share your solution with the community on how you managed to do the action for video player?

---

<div class="post-metadata">

### Author: ![Luca\_Trianti](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/luca_trianti/32/4775_2.png) [@Luca\_Trianti](https://forum.convai.com/u/Luca_Trianti)
#### Post date: [July 1, 2025, 10:08am UTC](https://forum.convai.com/t/play-videos-on-command/4375/9 "2025-07-01T10:08:17Z")

</div>

So, there are two main classes: one being the “media handler” and the other one being the “api handler”.

Info:

- One script handles the API: sends user text/audio to Convai, receives the AI’s response, plays the voice audio if included.
- The other one intercepts the AI’s response text, looks for patterns like “video of…” or other language variants, and uses fuzzy matching to find the closest local video listed in a`videoList.txt` file (containing the video file names, and I know, it’s not very dynamic).
- If a match is found, it shows the video UI and plays the corresponding video from the local folder.
- Video titles are loaded asynchronously from `videoList.txt` in `StreamingAssets/Videos`, making it easy to update the list without recompiling.
- For fuzzy matching, I used **FuzzySharp** (NuGet package) to compare the requested video name with available titles and trigger playback when the match confidence exceeds a threshold (I set it at 30%).
- I handle platform differences by copying the video to `Application.persistentDataPath` before playing it, which is especially needed on Android where direct access to `StreamingAssets` isn’t possible.
- Commands work across multiple languages by checking for keywords like:
- “video of” (English)
- “video di” (Italian)
- “vidéo de” (French)
- etc.
- Example workflow:

1. User says: _“I’d like to see the video of -insert video title here-.”_
2. Convai responds: _“Here is the video of -insert video title here-.”_
3. The media handler parses “video of -insert video title here-”, matches it to the closest video, and plays it automatically.

Here are the links to the 2 classes:

> **[ConvaiAPIHandler — Codefile](https://codefile.io/f/MRVOanbQaT)**
>
> Create collaborative code files online for your technical interviews, pair programming, teaching, etc.

> **[ConvaiMediaHandler — Codefile](https://codefile.io/f/saIOcJyWWO)**
>
> Create collaborative code files online for your technical interviews, pair programming, teaching, etc.

The ConvaiAPIHandler is attached to an empty game object, while the ConvaiMediaHandler is attached directly to the canvas of the video player.

If you have any questions please ask.

---

<div class="post-metadata">

### Author: ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)
#### Post date: [July 8, 2025, 5:41pm UTC](https://forum.convai.com/t/play-videos-on-command/4375/10 "2025-07-08T17:41:17Z")

</div>


