Adding cloudinary playList widget in React - reactjs

I have React app running videos from cloudinary. I have managed to edit Video tag but want to also add playlistWidget. Where does this fit into code/Video tag? The example provided on cloudinary is for javascript not React.
https://cloudinary.com/documentation/video_player_customization
Here is ex of my component with cloudinary player.
import React from "react";
import axios from "axios";
import "./VideoPlayer.css"
import { inDev } from "../API";
const devAPI = "http://localhost:8081/api/";
const baseAPI = "api/";
import {Image, Video, Transformation, CloudinaryContext} from 'cloudinary-react';
class Player extends React.Component {
constructor(props) {
super(props);
this.state = {
WelcomeVideo:"https://res.cloudinary.com/Name/video/upload/v1594509086/ab7qqxjexpwfv4j7kzj2x.mp4",
Logo:"https://res.cloudinary.com/example/image/upload/v1599423081/Logo1.png",
};
}
render() {
return ( <div style={{textAlign: "center"}}>
<h1 style={{fontSize:"60px"}}>Video of Week!</h1>
<Video
id="example-player"
cloudName="demo"
src={this.state.WelcomeVideo}
publicId="cat"
controls
autoPlay="true"
preload= "auto"
class="cld-video-player"
poster={this.state.Logo}
width= "400"
height="320"
fallback="Cannot display video"
/>
</div>
);
}
}
export default Player;
Updated recommendations per cloudinary https://cloudinary.com/documentation/video_player_playlists_recommendations#:~:text=playlist%20widget%20%2D%20A%20scrollable%20list,a%20full%20screen%20web%20browser.
import React, { Component } from "react";
import { Cloudinary } from "cloudinary-core";
import "cloudinary-video-player/dist/cld-video-player";
class PlayerCloud extends Component {
componentDidMount() {
// Setting video sources:
var source1 = { publicId: 'elephants', info: { title: 'My main movie',
subtitle: 'Something to know about the main movie' } }
var source2 = { publicId: 'cat', info: { title: 'Another great video',
subtitle: 'A great subtitle',
description: 'An interesting description of this video....' } }
var source3 = { publicId: 'dog', info: { title: 'Another interesting video1',
subtitle: 'Subtitle for video3', description: 'An interesting description of this video....' } }
// Specifying the recommendations for source1 as a fixed array of sources:
source1.recommendations = [source2, source3]
const cld = new Cloudinary({ cloud_name: "demo", secure: true });
const videoName = "elephants";
var demoplayer = cld.videoPlayer("some-video", {
publicId: source1.publicId,
controls: true,
preload: "auto",
muted: true,
autoplay: true,
width: 300,
autoShowRecommendations:true
});
}
render() {
return (
<div>
<video
id="some-video"
/>
</div>
);
}
}
export default PlayerCloud;

See this Codesandbox showing how to bind the video player code to a video tag. Once you are running a video player instead of an HTML 5 video tag, you can add functionality like the playList Widget
https://codesandbox.io/s/em2g0
https://cloudinary.com/documentation/video_player_playlists_recommendations#creating_a_playlist
The video player requires CSS that is in the index.html as well as binding functionality to a video tag.

Here's another react Sandbox which just shows a short video in the video player. [https://codesandbox.io/s/react-cld-video-player-v2-yfgxi?file=/src/VideoPlayerTest.js][1]
You can find more information about video player options and style here: https://cloudinary.com/documentation/cloudinary_video_player

Related

Show preview_video image/thumbnail as preview before playing video in React

I have video that I'd like to present as preview_video image/thumbnail before a user clicks on them for the full video. Is there a RN component to do this?
I have this code:
import { Video } from 'expo-av';
import VideoPlayer from 'expo-video-player';
import * as React from "react";
import {View} from "react-native";
import Header from "../../components/header/Header";
export default function VideoPlayerComponent(props) {
const { url } = props.route.params;
return (
<View>
<Header
title="Video"
goBack
/>
<VideoPlayer
style={{height:550}}
videoProps={{
shouldPlay: true,
resizeMode: Video.RESIZE_MODE_CONTAIN,
source: {
uri: url,
},
}}
/>
</View>
);
}
Seems you can try this component: https://docs.expo.dev/versions/latest/sdk/video-thumbnails/
const generateThumbnail = async () => {
try {
const { uri } = await VideoThumbnails.getThumbnailAsync(
'http://d23dyxeqlo5psv.cloudfront.net/big_buck_bunny.mp4',
{
time: 15000,
}
);
setImage(uri);
} catch (e) {
console.warn(e);
}
Then just include a condition when the video component is in its paused state, the thumbnail should be displayed with a higher zIndex.
Like describe here: react native video display thumbnail before video is played

ReactJS FullCalendar won't load events into calendar

Im grabbing the events dynamically from my backend API however when I make the call compoentWillMount() its as if the calendar is loading first and not getting the events so its not loading/displaying the events on the calendar. I keep looking through the docs and trying different solutions and cant get anything to succeed. My components code:
import React from "react";
import Tooltip from "tooltip.js";
import moment from 'moment';
import ErrorBoundary from "../Utils/ErrorBoundary";
import FullCalendar from "#fullcalendar/react";
import dayGridPlugin from "#fullcalendar/daygrid";
import interactionPlugin from "#fullcalendar/interaction";
import "#fullcalendar/core/main.css";
import "#fullcalendar/daygrid/main.css";
class ChoreCalendar extends React.Component {
constructor(props) {
super(props);
this.state = {
chores: [],
events: []
};
}
componentWillMount() {
fetch('http://localhost:8080/api/chores')
.then(res => res.json())
.then((data) => {
this.setState({ chores: data })
data.data.forEach(chore => {
this.state.events.push({
title: chore.title,
date: moment(chore.dueDate).format("YYYY-MM-DD"),
color: "green",
textColor: "white"
})
});
})
.catch(console.log)
}
eventRender(info) {
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.title,
placement: "top",
trigger: "click",
container: "body"
});
}
render() {
return (
<div className="ibox">
<div className="ibox-content">
<ErrorBoundary>
<FullCalendar
id="fullCalendar"
defaultView="dayGridMonth"
plugins={[dayGridPlugin, interactionPlugin]}
events={this.state.events}
eventRender={this.eventRender}
schedulerLicenseKey="GPL-My-Project-Is-Open-Source"
/>
</ErrorBoundary>
</div>
</div>
);
}
}
export default ChoreCalendar;
All I'm currently trying to do is dynamically grab the events and then load them into the calendar and have them show.
Add initialEvent prop in FullCalender Tag and assign it some state with initial values.

React Highcharts error

Looking for some help with the react wrapper for highcharts it seems to be throwing this error every-time I go to start the dev server for my application.
Error message Highcharts
With that Said I am sure that It is an issue with my code and not the Highcharts react wrapper. I am looking for some help to remedy this error. Thank you.
I am using another node wrapper for the Tradier API for market data and want to compare multiple tickers historically like the chart that is provided in Highchart's Demo. (Found here)
I Know I need to iterate through the returned JSON from Tradier- which
returns an array of objects for a particular ticker symbol.
{ day:
[ { date: '2017-01-03',
open: 115.8,
high: 116.33,
low: 114.76,
close: 116.15,
volume: 28781865 }...
]
I have Gone ahead and uploaded the app to a github repository. The code for the Highstock component I am trying to add in react is below, along with the github links for the used packages.
import React from 'react'
import Highcharts from 'highcharts/highstock'
import HighchartsReact from 'highcharts-react-official'
import Tradier from 'tradier-client';
class HighchartSector extends React.Component {
constructor(props){
super(props)
this.state = {
store: [],
openPrice: []
}
}
componentDidMount() {
const tradier = new Tradier('7svYXqoAjts9fGptLU7mtKo4Z4Oa', 'sandbox');
tradier.historical('LADR')
.then(history => history.day.map( result =>(
{
open: `${result.open}`,
})))
.then(newData => this.setState({openPrice: newData, store: newData}))
.catch(error => alert(error))
}
render() {
const { openPrice } = this.state;
const options = {
title: {
text: 'My stock chart'
},
series: [{
data: openPrice
}]
}
return (
<HighchartsReact
highcharts={Highcharts}
constructorType={'stockChart'}
options={options}
/>
)
}
}
export default HighchartSector
My Git Repo: HERE
Tradier vporta wrapper: HERE
Highcharts-Official React Wrapper: HERE

Using Phaser together with React

I am trying to understand how I could use React for rendering all the UI elements and Phaser for rendering a game (using Canvas or WebGL) within the React application.
One way would be to use React's componentDidMount, so after I have my HTML ready I can use a div id to render the Phaser content. In this case who does the rendering? React of Phaser?
If the mentioned way is not the right one, could you suggest another?
There is a module for this on Github called react-phaser. Here is a CodePen that does not use any separate module.
var PhaserContainer = React.createClass({
game: null,
...
componentDidMount: function(){
this.game = new Phaser.Game(800, 400, Phaser.AUTO, "phaser-container",
{
create: this.create,
update: this.update
});
},
...
render: function(){
return (
<div className="phaserContainer" id="phaser-container">
</div>
);
}
...
}
This is not my CodePen. Credit goes to Matthias.R
Check this new WebComponent to integrate Phaser with any other framework 👍 https://github.com/proyecto26/ion-phaser
Example:
import React, { Component } from 'react'
import Phaser from 'phaser'
import { IonPhaser } from '#ion-phaser/react'
class App extends Component {
state = {
initialize: false,
game: {
width: "100%",
height: "100%",
type: Phaser.AUTO,
scene: {}
}
}
render() {
const { initialize, game } = this.state
return (
<IonPhaser game={game} initialize={initialize} />
)
}
}

use videojs plugins in react Video JS

As doc mentioned I ve initialized video js in react by doing something like this ...
import React from 'react';
import videojs from 'video.js'
export default class VideoPlayer extends React.Component {
componentDidMount() {
// instantiate video.js
this.player = videojs(this.videoNode, this.props, function onPlayerReady() {
console.log('onPlayerReady', this)
});
}
// destroy player on unmount
componentWillUnmount() {
if (this.player) {
this.player.dispose()
}
}
// wrap the player in a div with a `data-vjs-player` attribute
// so videojs won't create additional wrapper in the DOM
// see https://github.com/videojs/video.js/pull/3856
render() {
return (
<div data-vjs-player>
<video ref={ node => this.videoNode = node } className="video-js"></video>
</div>
)
}
}
I want to integrate VideoJs Overlay plugin in this...
so i ve done something like this...
import React from 'react';
import videojs from 'video.js'
export default class VideoPlayer extends React.Component {
componentDidMount() {
// instantiate video.js
this.player = videojs(this.videoNode, this.props, function onPlayerReady() {
player.overlay({
content: 'Default overlay content',
debug: true,
overlays: [{
content: 'The video is playing!',
start: 'play',
end: 'pause'
}, {
start: 0,
end: 15,
align: 'bottom-left'
}, {
start: 15,
end: 30,
align: 'bottom'
}, {
start: 30,
end: 45,
align: 'bottom-right'
}, {
start: 20,
end: 'pause'
}]
});
});
}
// destroy player on unmount
componentWillUnmount() {
if (this.player) {
this.player.dispose()
}
}
render() {
return (
<div data-vjs-player>
<video ref={ node => this.videoNode = node } className="video-js" id="videojs-overlay-player"></video>
</div>
)
}
}
While doing this it give me error like player.overlay is not function...
and if i do videojs.registerPlugin('overlay', overlay);
and call overlay function it gives me error like component Overlay is undefined
How to workout videojs plugins in react way????
You need to import videojs-overlay package before you use it.
Follow these steps :
Install the plugin: npm i videojs-overlay --save
Import the package in Player class : import overlay from 'videojs-overlay';
Register the plugin before instantiating the player: videojs.registerPlugin('overlay', overlay);
Then, player.overlay({... will work as intended.

Resources