I have a Next. js app, and I want to embed YouTube placeholder so that I could play video in the chatbot itself. What should I do? Also, my front end is divided in two parts. Uh, one is web application, which is supported by Next. js, and other one is mobile application, which is built on React Native. Also, not just YouTube video. Uh, I want to support any kind of video. But first, let's try to embed YouTube videos.

Searching the Web

embed YouTube video Next.js chatbot react-player 2025

Searching the Web

react-native-youtube-iframe embed video chatbot React Native 2025

Here's a complete guide for both platforms.

Embedding YouTube (and any video) in your Chatbot

The Recommended Library: react-player

For both Next.js and general React use, react-player is the best single choice because:
  • Supports YouTube, Vimeo, Twitch, direct .mp4/.webm, and more - all with the same API
  • Works in Next.js with a simple dynamic import
  • Easily detects video URLs and auto-selects the right player

Part 1: Next.js (Web)

Step 1 - Install

npm install react-player

Step 2 - Create a VideoPlayer component

Because react-player uses browser APIs, it must be client-side only in Next.js:
// components/VideoPlayer.tsx
'use client';

import dynamic from 'next/dynamic';

const ReactPlayer = dynamic(() => import('react-player/lazy'), {
  ssr: false,
  loading: () => (
    <div className="video-placeholder">Loading player...</div>
  ),
});

interface VideoPlayerProps {
  url: string;
}

export default function VideoPlayer({ url }: VideoPlayerProps) {
  return (
    <div className="video-wrapper" style={{ position: 'relative', paddingTop: '56.25%' }}>
      <ReactPlayer
        url={url}
        controls
        width="100%"
        height="100%"
        style={{ position: 'absolute', top: 0, left: 0 }}
        config={{
          youtube: {
            playerVars: { showinfo: 1 },
          },
        }}
      />
    </div>
  );
}
The paddingTop: 56.25% trick maintains a 16:9 aspect ratio automatically.

Step 3 - Use it in your chatbot message renderer

In whatever component renders chat messages, detect video URLs and swap in the player:
// components/ChatMessage.tsx
'use client';

import VideoPlayer from './VideoPlayer';

function isVideoUrl(text: string): boolean {
  return (
    text.startsWith('https://www.youtube.com/') ||
    text.startsWith('https://youtu.be/') ||
    text.startsWith('https://vimeo.com/') ||
    /\.(mp4|webm|ogg)$/i.test(text)
  );
}

export default function ChatMessage({ content }: { content: string }) {
  if (isVideoUrl(content.trim())) {
    return <VideoPlayer url={content.trim()} />;
  }

  return <p>{content}</p>;
}

Step 4 - Allow YouTube in next.config.js

If you have a Content Security Policy or are using next/image domains, add this:
// next.config.js
const nextConfig = {
  async headers() {
    return [
      {
        source: '/(.*)',
        headers: [
          {
            key: 'Content-Security-Policy',
            // Permit YouTube iframes
            value: "frame-src 'self' https://www.youtube.com https://player.vimeo.com;",
          },
        ],
      },
    ];
  },
};
module.exports = nextConfig;

Part 2: React Native (Mobile)

react-player does not work in React Native. Use react-native-youtube-iframe for YouTube, and for general video, use react-native-video.

Install

npm install react-native-youtube-iframe
# For general video support later:
npm install react-native-video

YouTube player component

// components/VideoPlayer.native.tsx
import React, { useRef } from 'react';
import { View, StyleSheet } from 'react-native';
import YoutubePlayer from 'react-native-youtube-iframe';

function extractYouTubeId(url: string): string | null {
  const match = url.match(
    /(?:youtube\.com\/(?:watch\?v=|embed\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})/
  );
  return match ? match[1] : null;
}

interface VideoPlayerProps {
  url: string;
}

export default function VideoPlayer({ url }: VideoPlayerProps) {
  const videoId = extractYouTubeId(url);

  if (!videoId) return null;

  return (
    <View style={styles.container}>
      <YoutubePlayer
        height={220}
        videoId={videoId}
        play={false}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    width: '100%',
    borderRadius: 8,
    overflow: 'hidden',
  },
});

Use it in your chat message renderer

// components/ChatMessage.native.tsx
import React from 'react';
import { Text } from 'react-native';
import VideoPlayer from './VideoPlayer.native';

function isYouTubeUrl(text: string): boolean {
  return (
    text.includes('youtube.com/watch') ||
    text.includes('youtu.be/')
  );
}

export default function ChatMessage({ content }: { content: string }) {
  if (isYouTubeUrl(content.trim())) {
    return <VideoPlayer url={content.trim()} />;
  }
  return <Text>{content}</Text>;
}

Extending to Any Video (Future-proofing)

PlatformLibrarySupports
Next.js / Webreact-playerYouTube, Vimeo, Twitch, MP4, HLS, DASH, and more
React Nativereact-native-videoMP4, HLS, local files
React Nativereact-native-youtube-iframeYouTube only
When you're ready to support non-YouTube URLs in React Native, react-native-video handles direct video files. You can combine both - check if the URL is a YouTube URL and render YoutubePlayer, otherwise fall back to react-native-video.

Quick Summary

  1. Next.js: Install react-player, wrap it in a dynamic import with ssr: false, drop <VideoPlayer url={...} /> into your chat message renderer.
  2. React Native: Install react-native-youtube-iframe, extract the video ID from the URL, render <YoutubePlayer videoId={...} />.
  3. Both approaches use the same pattern: detect a video URL in the chat message -> swap in the player component.
  4. react-player on web already handles virtually any video source, so "any video" support is free on Next.js.
This is a shared conversation. Sign in to Orris to start your own chat.