Skip to content

Commit

Permalink
fix: remove srcObject attribute if next uri is not a MediaStream (#1121)
Browse files Browse the repository at this point in the history
  • Loading branch information
komachi authored Jan 20, 2021
1 parent ffdd813 commit 7e69418
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/players/FilePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export default class FilePlayer extends Component {
this.removeListeners(this.prevPlayer, prevProps.url)
this.addListeners(this.player)
}

if (
this.props.url !== prevProps.url &&
!isMediaStream(this.props.url)
) {
this.player.removeAttribute('srcObject')
}
}

componentWillUnmount () {
Expand Down
10 changes: 10 additions & 0 deletions test/players/FilePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,13 @@ test('auto width/height', t => {
</video>
))
})

test('clear srcObject on url change', t => {
const url = new MockMediaStream()
const wrapper = shallow(<FilePlayer url={url} config={config} />)
const instance = wrapper.instance()
instance.player.removeAttribute = sinon.fake()
instance.load(url)
wrapper.setProps({ url: 'file.mpv' })
t.true(instance.player.removeAttribute.calledOnceWith('srcObject'))
})

0 comments on commit 7e69418

Please sign in to comment.