2020-02-27 05:55:56 +08:00
|
|
|
|
2019-07-16 04:12:07 +08:00
|
|
|
import ReactPlayer from 'react-player';
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2020-07-01 03:20:24 +08:00
|
|
|
import Panopto from './custom-players/panopto';
|
|
|
|
|
2022-10-06 02:53:44 +08:00
|
|
|
const YOUTUBE_SHORTS_REGEX = new RegExp(/^(?:https?:\/\/)?(?:www\.)?(youtube\.com\/shorts)\/.+$/);
|
|
|
|
|
2020-07-01 03:20:24 +08:00
|
|
|
const isUrlValid = (url) => {
|
2022-10-06 02:53:44 +08:00
|
|
|
if (YOUTUBE_SHORTS_REGEX.test(url)) {
|
|
|
|
const shortsUrl = url.replace('shorts/', 'watch?v=');
|
|
|
|
|
|
|
|
return /^https.*$/.test(shortsUrl) && (ReactPlayer.canPlay(shortsUrl) || Panopto.canPlay(shortsUrl));
|
|
|
|
}
|
|
|
|
|
2021-02-10 02:24:21 +08:00
|
|
|
return /^https.*$/.test(url) && (ReactPlayer.canPlay(url) || Panopto.canPlay(url));
|
2022-10-06 02:53:44 +08:00
|
|
|
};
|
2019-01-16 04:44:41 +08:00
|
|
|
|
2021-06-03 02:07:03 +08:00
|
|
|
// Convert state (Number) to playing (Boolean)
|
|
|
|
const getPlayingState = (state) => {
|
|
|
|
if (state === 1) return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2018-11-30 01:24:02 +08:00
|
|
|
export {
|
2019-01-16 04:44:41 +08:00
|
|
|
isUrlValid,
|
2021-06-03 02:07:03 +08:00
|
|
|
getPlayingState,
|
2018-11-30 01:24:02 +08:00
|
|
|
};
|