DynTube API
  • Welcome!
  • Key Concepts
  • Quick Start
  • Reference
    • Videos
      • Video Upload via File (Server Side)
      • Video Upload via URL (server side)
      • HTML-Form Client Side Video Uploads
      • Get Video Status
      • Get Videos
      • Get Video
      • Update Video
      • Delete Video
      • Download Original Video
      • Get Video for Mobile App/Custom Player
      • Update Video Image
      • Add Video Captions/Chapters/Subtitles
      • Delete Video Captions/Subtitles/Chapters
      • Create Expirable Links
      • Get Collected Emails
      • Setting Up Webhooks
      • Copy call-to-action (CTA) to Videos
      • Token Authentication
    • Projects
      • Create Project
      • Update a Project
      • Get Projects
      • Get a Project
      • Delete a Project
      • Set default CTA for Project
    • Live Streaming
      • Create a Live Stream
      • Update a Live Stream
      • Get Live Streams
      • Get a Live Stream
      • Count Live Streams
      • Live Streams Limit
      • Get Live Streaming Recording
      • Delete a Live Stream
      • Service and Regions for live streams
    • Channels
      • Get Channels
      • Get Channel
      • Delete Channel
    • Subscriptions
      • Create a Plan
      • Create a Member
      • Attach Plan To Member
      • Get Plans
      • Get Members
      • Get Member's Plans
      • Delete a Plan
    • Analytics
      • Use your User Ids in Analytics
      • Get Video Analytics
    • Javascript Events Methods
      • Plain Javascript Events & Methods
      • Control the Player using React
      • Control the Player in Vue.js
    • Developer Resources
      • How to embed DynTube player in Next.Js
      • How to embed the video player in React
      • How to play DynTube videos in React Native
      • ExoPlayer app to play HLS videos
      • How to embed videos & channels dynamically
      • How to Import Vimeo Videos into DynTube
Powered by GitBook
On this page
  • Embed Javascript Based Code in React
  • Embed Iframe Code in React
  1. Reference
  2. Developer Resources

How to embed the video player in React

Embed Javascript Based Code in React

import React, { useEffect } from 'react';

const VideoEmbed = () => {
  useEffect(() => {
    // Create script element and add to the DOM
    const script = document.createElement('script');
    script.src = 'https://embed.dyntube.com/v1.0/dyntube.js';
    script.async = true;
    document.body.appendChild(script);

    // Clean up the script on component unmount
    return () => {
      document.body.removeChild(script);
    };
  }, []);

  return (
    <div>
      <h1>Embedded Video</h1>
      {/* Dyntube embed div */}
      <div data-dyntube-key="Q2rVFPmBlUKujzxXBJ3faw"></div>
    </div>
  );
};

export default VideoEmbed;

Embed Iframe Code in React

import React from 'react';

const VideoEmbed = () => {
  return (
    <div
      style={{
        position: 'relative',
        width: '100%',
        overflow: 'hidden',
        paddingTop: '57.25%',
      }}
    >
      <iframe
        style={{
          position: 'absolute',
          top: 0,
          left: 0,
          bottom: 0,
          right: 0,
          width: '100%',
          height: '100%',
          border: 'none',
        }}
        allow="autoplay; fullscreen"
        webkitAllowFullScreen
        mozAllowFullScreen
        allowFullScreen
        src="https://videos.dyntube.com/iframes/Q2rVFPmBlUKujzxXBJ3faw"
        title="Caminandes USE"
      ></iframe>
    </div>
  );
};

export default VideoEmbed;
PreviousHow to embed DynTube player in Next.JsNextHow to play DynTube videos in React Native

Last updated 8 months ago