1 | import React from 'react'
|
2 |
|
3 | export default class Sources {
|
4 | constructor(inSources) {
|
5 | this.sources = inSources
|
6 | }
|
7 |
|
8 | createSourceElement = (source, key = 0) => {
|
9 | try{
|
10 | if (typeof source === 'string') {
|
11 | const acceptedFormats = ['webm', 'ogv', 'mp4', 'mov', 'flv']
|
12 | const test = /\.([0-9a-z]{1,5})$/
|
13 | const result = test.exec(source)
|
14 | let format = result[1]
|
15 | if (!acceptedFormats.includes(format)) {
|
16 | console.warn(`An invalid file extension was provided for ${source}`)
|
17 | }
|
18 | if (format === 'ogv') {
|
19 | format = 'ogg'
|
20 | }
|
21 | return <source src={source} type={`video/${format}`} key={key} />
|
22 | } else {
|
23 | console.warn(`A string was not provided as a source for ${source}`)
|
24 | }
|
25 | } catch (err) {
|
26 | console.error(err)
|
27 | }
|
28 | }
|
29 |
|
30 | render = () => {
|
31 | try {
|
32 | let output = []
|
33 | if (Array.isArray(this.sources)){
|
34 | output = this.sources.map((source, index) => {
|
35 | return this.createSourceElement(source, index)
|
36 | })
|
37 | } else {
|
38 | output = [this.createSourceElement(this.sources, )]
|
39 | }
|
40 | return output
|
41 | } catch (err) {
|
42 | console.error(err)
|
43 | }
|
44 | }
|
45 | }
|
46 |
|
\ | No newline at end of file |