Adding support to youtube videos.
This commit is contained in:
@@ -8,13 +8,20 @@ import { WebView } from 'react-native-webview';
|
||||
|
||||
const videoIdF = (content) => {
|
||||
let vimeoTag = content.match(/@vimeo:[0-9]+/);
|
||||
let youtubeTag = content.match(/@youtube:[0-z]+/);
|
||||
if (!vimeoTag && !youtubeTag) return [];
|
||||
let tag = youtubeTag || vimeoTag || hslTag;
|
||||
if (!vimeoTag) return [];
|
||||
let tag = vimeoTag;
|
||||
tag = tag[0].substring(1);
|
||||
return tag.split(':');
|
||||
};
|
||||
|
||||
const youtubeIdF = (content) => {
|
||||
let youtubeTag = content.match(/@youtube:[0-z]+/);
|
||||
if (!youtubeTag) return '';
|
||||
let tag = youtubeTag;
|
||||
tag = tag[0].substring(1);
|
||||
return tag.split(':')[1];
|
||||
};
|
||||
|
||||
const hlsIdF = (content) => {
|
||||
let hslTag = content.match(/@hls:.+\w/);
|
||||
if (!hslTag) return '';
|
||||
@@ -51,6 +58,7 @@ let Media = (props) => {
|
||||
const videosId = videoIdF(props.content);
|
||||
const hlsUrl = hlsIdF(props.content);
|
||||
const iframeSrc = iframeTagF(props.content) || [];
|
||||
const youtubeId = youtubeIdF(props.content);
|
||||
const [videosFiles, setVideosFiles] = useState([]);
|
||||
const [poster, setPoster] = useState('');
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
@@ -97,6 +105,11 @@ let Media = (props) => {
|
||||
style={styles.iframe}
|
||||
source={{ uri: iframeSrc[1] }}
|
||||
/> : <></>;
|
||||
const youtubeEmb = youtubeId.length ?
|
||||
<WebView
|
||||
style={styles.iframe}
|
||||
source={{ uri: "https://www.youtube.com/embed/" + youtubeId + "?fs=0" }}
|
||||
/> : <></>;
|
||||
const renderImages = (({ item }) => {
|
||||
return (<Image source={{ uri: item[1] }} style={styles.flatlistImages} />);
|
||||
});
|
||||
@@ -125,6 +138,7 @@ let Media = (props) => {
|
||||
{video}
|
||||
{video2}
|
||||
{iframe}
|
||||
{youtubeEmb}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user