[PlayerPanel] youtube overlayContents 안뜨는 현상 수정
This commit is contained in:
@@ -1,102 +1,138 @@
|
|||||||
|
import React, { useCallback, useMemo, useRef } from "react";
|
||||||
|
|
||||||
import ReactPlayer from "react-player";
|
import ReactPlayer from "react-player";
|
||||||
import handle from '@enact/core/handle';
|
|
||||||
import React, { useCallback, useRef, useMemo } from "react";
|
|
||||||
|
|
||||||
var handledMediaEventsMap =
|
import handle from "@enact/core/handle";
|
||||||
['onReady', 'onStart', 'onPlay', 'onProgress', 'onDuration', 'onPause', 'onBuffer', 'onBufferEnd', 'onSeek', 'onEnded', 'onError'];
|
|
||||||
|
|
||||||
export default function TReactPlayer({mediaEventsMap=handledMediaEventsMap, videoRef, url, ...rest}) {
|
var handledMediaEventsMap = [
|
||||||
|
"onReady",
|
||||||
|
"onStart",
|
||||||
|
"onPlay",
|
||||||
|
"onProgress",
|
||||||
|
"onDuration",
|
||||||
|
"onPause",
|
||||||
|
"onBuffer",
|
||||||
|
"onBufferEnd",
|
||||||
|
"onSeek",
|
||||||
|
"onEnded",
|
||||||
|
"onError",
|
||||||
|
];
|
||||||
|
|
||||||
|
export default function TReactPlayer({
|
||||||
|
mediaEventsMap = handledMediaEventsMap,
|
||||||
|
videoRef,
|
||||||
|
url,
|
||||||
|
overlayLoading,
|
||||||
|
setOverlayLoading,
|
||||||
|
...rest
|
||||||
|
}) {
|
||||||
const playerRef = useRef(null);
|
const playerRef = useRef(null);
|
||||||
|
|
||||||
const handleEvent = useCallback((type)=> (ev)=> {
|
const handleEvent = useCallback(
|
||||||
if(type === 'onReady'){
|
(type) => (ev) => {
|
||||||
if(videoRef ){
|
if (type === "onReady") {
|
||||||
const videoNode = playerRef.current.getInternalPlayer();
|
if (videoRef) {
|
||||||
videoRef(videoNode);
|
if (!overlayLoading) {
|
||||||
if(videoNode.tagName && !Object.prototype.hasOwnProperty.call(videoNode, "proportionPlayed")){
|
setOverlayLoading(true);
|
||||||
Object.defineProperties(videoNode, {
|
}
|
||||||
'error': {
|
|
||||||
get: function() {
|
|
||||||
return videoNode.networkState === videoNode.NETWORK_NO_SOURCE;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'loading': {
|
|
||||||
get: function() {
|
|
||||||
return videoNode.readyState < videoNode.HAVE_ENOUGH_DATA;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'proportionLoaded': {
|
|
||||||
get: function() {
|
|
||||||
return videoNode.buffered.length &&videoNode.buffered.end(videoNode.buffered.length - 1) / videoNode.duration;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'proportionPlayed': {
|
|
||||||
get: function() {
|
|
||||||
return videoNode.currentTime / videoNode.duration;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}else if(!Object.prototype.hasOwnProperty.call(videoNode, "proportionPlayed")){//youtube
|
|
||||||
window.videoNode = videoNode;
|
|
||||||
videoNode.play = videoNode.playVideo;
|
|
||||||
videoNode.pause = videoNode.pauseVideo;
|
|
||||||
videoNode.seek = videoNode.seekTo;
|
|
||||||
Object.defineProperties(videoNode, {
|
|
||||||
'currentTime': {
|
|
||||||
get: function() {
|
|
||||||
return videoNode.getCurrentTime();
|
|
||||||
},
|
|
||||||
set: function(time){
|
|
||||||
videoNode.seekTo(time);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'duration':{
|
|
||||||
get: function() {
|
|
||||||
return videoNode.getDuration();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'paused':{
|
|
||||||
get: function() {
|
|
||||||
return videoNode.getPlayerState() !== 1;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'error': {
|
|
||||||
get: function() {
|
|
||||||
return !!videoNode?.playerInfo?.videoData?.errorCode;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'loading': {
|
|
||||||
get: function() {
|
|
||||||
return !videoNode?.playerInfo?.videoData?.isPlayable;
|
|
||||||
; //todo
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'proportionLoaded': {
|
|
||||||
get: function() {
|
|
||||||
return videoNode?.playerInfo?.videoBytesLoaded >= 1; //todo
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'proportionPlayed': {
|
|
||||||
get: function() {
|
|
||||||
return videoNode.getCurrentTime() / videoNode.getDuration();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
handle.forward('onLoadStart', {type, ev}, rest);
|
|
||||||
}
|
|
||||||
handle.forward('onUpdate', {type, ev}, rest);
|
|
||||||
},[videoRef]);
|
|
||||||
|
|
||||||
const handledMediaEvents = useMemo(()=>{
|
const videoNode = playerRef.current.getInternalPlayer();
|
||||||
|
videoRef(videoNode);
|
||||||
|
if (
|
||||||
|
videoNode.tagName &&
|
||||||
|
!Object.prototype.hasOwnProperty.call(videoNode, "proportionPlayed")
|
||||||
|
) {
|
||||||
|
Object.defineProperties(videoNode, {
|
||||||
|
error: {
|
||||||
|
get: function () {
|
||||||
|
return videoNode.networkState === videoNode.NETWORK_NO_SOURCE;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
loading: {
|
||||||
|
get: function () {
|
||||||
|
return videoNode.readyState < videoNode.HAVE_ENOUGH_DATA;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
proportionLoaded: {
|
||||||
|
get: function () {
|
||||||
|
return (
|
||||||
|
videoNode.buffered.length &&
|
||||||
|
videoNode.buffered.end(videoNode.buffered.length - 1) /
|
||||||
|
videoNode.duration
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
proportionPlayed: {
|
||||||
|
get: function () {
|
||||||
|
return videoNode.currentTime / videoNode.duration;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else if (
|
||||||
|
!Object.prototype.hasOwnProperty.call(videoNode, "proportionPlayed")
|
||||||
|
) {
|
||||||
|
//youtube
|
||||||
|
window.videoNode = videoNode;
|
||||||
|
videoNode.play = videoNode.playVideo;
|
||||||
|
videoNode.pause = videoNode.pauseVideo;
|
||||||
|
videoNode.seek = videoNode.seekTo;
|
||||||
|
Object.defineProperties(videoNode, {
|
||||||
|
currentTime: {
|
||||||
|
get: function () {
|
||||||
|
return videoNode.getCurrentTime();
|
||||||
|
},
|
||||||
|
set: function (time) {
|
||||||
|
videoNode.seekTo(time);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
duration: {
|
||||||
|
get: function () {
|
||||||
|
return videoNode.getDuration();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
paused: {
|
||||||
|
get: function () {
|
||||||
|
return videoNode.getPlayerState() !== 1;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
error: {
|
||||||
|
get: function () {
|
||||||
|
return !!videoNode?.playerInfo?.videoData?.errorCode;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
loading: {
|
||||||
|
get: function () {
|
||||||
|
return !videoNode?.playerInfo?.videoData?.isPlayable; //todo
|
||||||
|
},
|
||||||
|
},
|
||||||
|
proportionLoaded: {
|
||||||
|
get: function () {
|
||||||
|
return videoNode?.playerInfo?.videoBytesLoaded >= 1; //todo
|
||||||
|
},
|
||||||
|
},
|
||||||
|
proportionPlayed: {
|
||||||
|
get: function () {
|
||||||
|
return videoNode.getCurrentTime() / videoNode.getDuration();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
handle.forward("onLoadStart", { type, ev }, rest);
|
||||||
|
}
|
||||||
|
handle.forward("onUpdate", { type, ev }, rest);
|
||||||
|
},
|
||||||
|
[videoRef, overlayLoading]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handledMediaEvents = useMemo(() => {
|
||||||
const events = {};
|
const events = {};
|
||||||
for (let i=0; i< mediaEventsMap.length; i++) {
|
for (let i = 0; i < mediaEventsMap.length; i++) {
|
||||||
const eventName = mediaEventsMap[i];
|
const eventName = mediaEventsMap[i];
|
||||||
events[eventName] = handleEvent(eventName);
|
events[eventName] = handleEvent(eventName);
|
||||||
}
|
}
|
||||||
return events;
|
return events;
|
||||||
},[handleEvent, mediaEventsMap]);
|
}, [handleEvent, mediaEventsMap]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactPlayer
|
<ReactPlayer
|
||||||
@@ -106,6 +142,6 @@ export default function TReactPlayer({mediaEventsMap=handledMediaEventsMap, vide
|
|||||||
{...handledMediaEvents}
|
{...handledMediaEvents}
|
||||||
{...rest}
|
{...rest}
|
||||||
playsinline // Add playsinline attribute here
|
playsinline // Add playsinline attribute here
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2110,6 +2110,7 @@ const VideoPlayerBase = class extends React.Component {
|
|||||||
orderPhnNo,
|
orderPhnNo,
|
||||||
captionEnable,
|
captionEnable,
|
||||||
overlayLoading,
|
overlayLoading,
|
||||||
|
setOverlayLoading,
|
||||||
...mediaProps
|
...mediaProps
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
@@ -2222,7 +2223,11 @@ const VideoPlayerBase = class extends React.Component {
|
|||||||
(VideoComponent &&
|
(VideoComponent &&
|
||||||
(((typeof VideoComponent === "function" ||
|
(((typeof VideoComponent === "function" ||
|
||||||
typeof VideoComponent === "string") && (
|
typeof VideoComponent === "string") && (
|
||||||
<VideoComponent {...mediaProps} />
|
<VideoComponent
|
||||||
|
{...mediaProps}
|
||||||
|
overlayLoading={overlayLoading}
|
||||||
|
setOverlayLoading={setOverlayLoading}
|
||||||
|
/>
|
||||||
)) ||
|
)) ||
|
||||||
(React.isValidElement(VideoComponent) &&
|
(React.isValidElement(VideoComponent) &&
|
||||||
React.cloneElement(VideoComponent, mediaProps)))) ||
|
React.cloneElement(VideoComponent, mediaProps)))) ||
|
||||||
|
|||||||
@@ -1298,6 +1298,7 @@ const PlayerPanel = ({
|
|||||||
videoVerticalVisible={videoVerticalVisible}
|
videoVerticalVisible={videoVerticalVisible}
|
||||||
isSubtitleActive={isSubtitleActive}
|
isSubtitleActive={isSubtitleActive}
|
||||||
overlayLoading={overlayLoading}
|
overlayLoading={overlayLoading}
|
||||||
|
setOverlayLoading={setOverlayLoading}
|
||||||
>
|
>
|
||||||
{typeof window === "object" && window.PalmSystem && (
|
{typeof window === "object" && window.PalmSystem && (
|
||||||
<source src={currentPlayingUrl} type="application/mpegurl" />
|
<source src={currentPlayingUrl} type="application/mpegurl" />
|
||||||
|
|||||||
Reference in New Issue
Block a user