Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve codec unsupported detection #1711

Merged
merged 8 commits into from
Oct 13, 2019
25 changes: 7 additions & 18 deletions src/renderer/pages/player-page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* global HTMLMediaElement */

const React = require('react')
const Bitfield = require('bitfield')
const prettyBytes = require('prettier-bytes')
Expand Down Expand Up @@ -56,6 +54,13 @@ function renderMedia (state) {
mediaElement.pause()
} else if (!state.playing.isPaused && mediaElement.paused) {
mediaElement.play()
.then(
() => dispatch('mediaSuccess'),
(err) => {
console.error(`Error playing mediaElement: ${err.name}`)
dispatch('mediaError', 'Codec unsupported')
}
)
}
// When the user clicks or drags on the progress bar, jump to that position
if (state.playing.jumpToTime != null) {
Expand Down Expand Up @@ -127,10 +132,8 @@ function renderMedia (state) {
onLoadedMetadata={onLoadedMetadata}
onEnded={onEnded}
onStalled={dispatcher('mediaStalled')}
onError={dispatcher('mediaError')}
onTimeUpdate={dispatcher('mediaTimeUpdate')}
onEncrypted={dispatcher('mediaEncrypted')}
onCanPlay={onCanPlay}
>
{trackTags}
</MediaTagName>
Expand Down Expand Up @@ -168,20 +171,6 @@ function renderMedia (state) {
if (state.window.isFullScreen) dispatch('toggleFullScreen')
}
}

function onCanPlay (e) {
const elem = e.target
if (elem.readyState < HTMLMediaElement.HAVE_FUTURE_DATA) return
if (state.playing.type === 'video' &&
elem.webkitVideoDecodedByteCount === 0) {
dispatch('mediaError', 'Video codec unsupported')
} else if (elem.webkitAudioDecodedByteCount === 0) {
dispatch('mediaError', 'Audio codec unsupported')
} else {
dispatch('mediaSuccess')
elem.play()
}
}
}

function renderOverlay (state) {
Expand Down