-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "react-player", | ||
"description": "A react component for playing a variety of URLs, including file paths, YouTube, SoundCloud, Streamable and Vimeo", | ||
"description": "A react component for playing a variety of URLs, including file paths, YouTube, SoundCloud, Streamable, Vidme and Vimeo", | ||
"main": "dist/ReactPlayer.js", | ||
"authors": [ | ||
"Pete Cook <[email protected]> (http://github.com/cookpete)" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import FilePlayer from './FilePlayer' | ||
|
||
const RESOLVE_URL = 'https://api.vid.me/videoByUrl/' | ||
const MATCH_URL = /^https?:\/\/vid.me\/([a-z0-9]+)$/ | ||
|
||
const cache = {} // Cache song data requests | ||
|
||
export default class Vidme extends FilePlayer { | ||
static displayName = 'Vidme' | ||
static canPlay (url) { | ||
return MATCH_URL.test(url) | ||
} | ||
getData (url) { | ||
const { onError } = this.props | ||
const id = url.match(MATCH_URL)[1] | ||
if (cache[id]) { | ||
return Promise.resolve(cache[id]) | ||
} | ||
return window.fetch(RESOLVE_URL + id) | ||
.then(response => { | ||
if (response.status === 200) { | ||
cache[id] = response.json() | ||
return cache[id] | ||
} else { | ||
onError(new Error('Vidme track could not be resolved')) | ||
} | ||
}) | ||
} | ||
load (url) { | ||
const { onError } = this.props | ||
this.stop() | ||
this.getData(url).then(data => { | ||
if (!this.mounted) return | ||
this.player.src = data.video.complete_url | ||
}, onError) | ||
} | ||
} |