Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Remove "The play() request was interrupted by a call to pause()" #852

Merged
merged 2 commits into from
Aug 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/components/Audioplayer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ export class Audioplayer extends Component {
if (!currentFile) return false;

if (isPlaying) {
currentFile.play();
const playPromise = currentFile.play();
// Catch/silence error when a pause interrupts a play request
// on browsers which return a promise
if (playPromise !== undefined && typeof playPromise.then === 'function') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about playPromise && playPromise.then ? less code fewer bugs :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, could have done that 👍

playPromise.then(null, () => {});
}
} else {
currentFile.pause();
}
Expand Down Expand Up @@ -374,7 +379,7 @@ export class Audioplayer extends Component {
file.onloadeddata = null; // eslint-disable-line no-param-reassign
file.ontimeupdate = null; // eslint-disable-line no-param-reassign
file.onplay = null; // eslint-disable-line no-param-reassign
file.onPause = null; // eslint-disable-line no-param-reassign
file.onpause = null; // eslint-disable-line no-param-reassign
file.onended = null; // eslint-disable-line no-param-reassign
file.onprogress = null; // eslint-disable-line no-param-reassign
};
Expand Down Expand Up @@ -471,7 +476,8 @@ export class Audioplayer extends Component {

return (
<div
className={`${isPlaying && style.isPlaying} ${style.container} ${className}`}
className={`${isPlaying &&
style.isPlaying} ${style.container} ${className}`}
>
<Wrapper>
{currentFile &&
Expand All @@ -493,9 +499,7 @@ export class Audioplayer extends Component {
id="player.currentVerse"
defaultMessage="Ayah"
/>
:
{' '}
{currentVerse.verseKey.split(':')[1]}
: {currentVerse.verseKey.split(':')[1]}
</ControlItem>
<ControlItem>
{this.renderPreviousButton()}
Expand Down