Skip to content

Commit

Permalink
Add support for MediaStream objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Webmaster1116 committed May 17, 2018
1 parent 46072be commit bf5bea7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ As of Chrome 66, [videos must be `muted` in order to play automatically](https:/

Prop | Description | Default
---- | ----------- | -------
`url` | The url of a video or song to play
`url` | The url of a video or song to play<br/>&nbsp;&nbsp;Can be an [array](#multiple-sources-and-tracks) or [`MediaStream`](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream) object
`playing` | Set to `true` or `false` to pause or play the media | `false`
`loop` | Set to `true` or `false` to loop the media | `false`
`controls` | Set to `true` or `false` to display native player controls<br />&nbsp;&nbsp;Vimeo, Twitch and Wistia player will always display controls | `false`
Expand Down
12 changes: 11 additions & 1 deletion src/players/FilePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ function canPlay (url) {
}
return false
}
if (url instanceof window.MediaStream) {
return true
}
return (
AUDIO_EXTENSIONS.test(url) ||
VIDEO_EXTENSIONS.test(url) ||
Expand Down Expand Up @@ -115,6 +118,13 @@ export class FilePlayer extends Component {
this.dash.getDebug().setLogToBrowserConsole(false)
})
}
if (url instanceof window.MediaStream) {
try {
this.player.srcObject = url
} catch (e) {
this.player.src = window.URL.createObjectURL(url)
}
}
}
play () {
const promise = this.player.play()
Expand Down Expand Up @@ -170,7 +180,7 @@ export class FilePlayer extends Component {
getSource (url) {
const useHLS = this.shouldUseHLS(url)
const useDASH = this.shouldUseDASH(url)
if (url instanceof Array || useHLS || useDASH) {
if (url instanceof Array || url instanceof window.MediaStream || useHLS || useDASH) {
return undefined
}
if (MATCH_DROPBOX_URL.test(url)) {
Expand Down
2 changes: 1 addition & 1 deletion src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
const { string, bool, number, array, oneOfType, shape, object, func } = PropTypes

export const propTypes = {
url: oneOfType([ string, array ]),
url: oneOfType([ string, array, object ]),
playing: bool,
loop: bool,
controls: bool,
Expand Down

0 comments on commit bf5bea7

Please sign in to comment.