Improve codec unsupported detection
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
/* global HTMLMediaElement */
|
|
||||||
|
|
||||||
const React = require('react')
|
const React = require('react')
|
||||||
const Bitfield = require('bitfield')
|
const Bitfield = require('bitfield')
|
||||||
const prettyBytes = require('prettier-bytes')
|
const prettyBytes = require('prettier-bytes')
|
||||||
@@ -56,6 +54,14 @@ function renderMedia (state) {
|
|||||||
mediaElement.pause()
|
mediaElement.pause()
|
||||||
} else if (!state.playing.isPaused && mediaElement.paused) {
|
} else if (!state.playing.isPaused && mediaElement.paused) {
|
||||||
mediaElement.play()
|
mediaElement.play()
|
||||||
|
.then(() => {
|
||||||
|
dispatch('mediaSuccess')
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
if (err.name === 'NotSupportedError') {
|
||||||
|
dispatch('mediaError', 'Codec unsupported')
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// When the user clicks or drags on the progress bar, jump to that position
|
// When the user clicks or drags on the progress bar, jump to that position
|
||||||
if (state.playing.jumpToTime != null) {
|
if (state.playing.jumpToTime != null) {
|
||||||
@@ -127,10 +133,8 @@ function renderMedia (state) {
|
|||||||
onLoadedMetadata={onLoadedMetadata}
|
onLoadedMetadata={onLoadedMetadata}
|
||||||
onEnded={onEnded}
|
onEnded={onEnded}
|
||||||
onStalled={dispatcher('mediaStalled')}
|
onStalled={dispatcher('mediaStalled')}
|
||||||
onError={dispatcher('mediaError')}
|
|
||||||
onTimeUpdate={dispatcher('mediaTimeUpdate')}
|
onTimeUpdate={dispatcher('mediaTimeUpdate')}
|
||||||
onEncrypted={dispatcher('mediaEncrypted')}
|
onEncrypted={dispatcher('mediaEncrypted')}
|
||||||
onCanPlay={onCanPlay}
|
|
||||||
>
|
>
|
||||||
{trackTags}
|
{trackTags}
|
||||||
</MediaTagName>
|
</MediaTagName>
|
||||||
@@ -168,20 +172,6 @@ function renderMedia (state) {
|
|||||||
if (state.window.isFullScreen) dispatch('toggleFullScreen')
|
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) {
|
function renderOverlay (state) {
|
||||||
|
|||||||
Reference in New Issue
Block a user