-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
55 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
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,35 @@ | ||
import FilePlayer from './FilePlayer' | ||
|
||
const RESOLVE_URL = 'https://api.streamable.com/videos/' | ||
const MATCH_URL = /^https?:\/\/streamable.com\/([a-z0-9]+)$/ | ||
|
||
const cache = {} // Cache song data requests | ||
|
||
export default class Streamable extends FilePlayer { | ||
static displayName = 'Streamable' | ||
static canPlay (url) { | ||
return MATCH_URL.test(url) | ||
} | ||
getData (url) { | ||
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 { | ||
this.props.onError(new Error('Streamable track could not be resolved')) | ||
} | ||
}) | ||
} | ||
load (url) { | ||
this.stop() | ||
this.getData(url).then(data => { | ||
if (!this.mounted) return | ||
this.player.src = data.files.mp4.url | ||
}, this.props.onError) | ||
} | ||
} |