Merge pull request #1711 from hicom150/fix_codec_unsupported_detection
Improve codec unsupported detection
This commit is contained in:
@@ -25,7 +25,8 @@ function init () {
|
||||
title: 'About ' + config.APP_WINDOW_TITLE,
|
||||
useContentSize: true,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableBlinkFeatures: 'AudioVideoTracks'
|
||||
},
|
||||
width: 300
|
||||
})
|
||||
|
||||
@@ -44,7 +44,8 @@ function init (state, options) {
|
||||
useContentSize: true, // Specify web page size without OS chrome
|
||||
width: initialBounds.width,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableBlinkFeatures: 'AudioVideoTracks'
|
||||
},
|
||||
x: initialBounds.x,
|
||||
y: initialBounds.y
|
||||
|
||||
@@ -26,7 +26,8 @@ function init () {
|
||||
title: 'webtorrent-hidden-window',
|
||||
useContentSize: true,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableBlinkFeatures: 'AudioVideoTracks'
|
||||
},
|
||||
width: 150
|
||||
})
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/* global HTMLMediaElement */
|
||||
|
||||
const React = require('react')
|
||||
const Bitfield = require('bitfield')
|
||||
const prettyBytes = require('prettier-bytes')
|
||||
@@ -130,7 +128,6 @@ function renderMedia (state) {
|
||||
onError={dispatcher('mediaError')}
|
||||
onTimeUpdate={dispatcher('mediaTimeUpdate')}
|
||||
onEncrypted={dispatcher('mediaEncrypted')}
|
||||
onCanPlay={onCanPlay}
|
||||
>
|
||||
{trackTags}
|
||||
</MediaTagName>
|
||||
@@ -148,15 +145,38 @@ function renderMedia (state) {
|
||||
</div>
|
||||
)
|
||||
|
||||
// As soon as we know the video dimensions, resize the window
|
||||
function onLoadedMetadata (e) {
|
||||
if (state.playing.type !== 'video') return
|
||||
const video = e.target
|
||||
const dimensions = {
|
||||
width: video.videoWidth,
|
||||
height: video.videoHeight
|
||||
const mediaElement = e.target
|
||||
|
||||
// check if we can decode video and audio track
|
||||
if (state.playing.type === 'video') {
|
||||
if (mediaElement.videoTracks.length === 0) {
|
||||
dispatch('mediaError', 'Video codec unsupported')
|
||||
}
|
||||
|
||||
if (mediaElement.audioTracks.length === 0) {
|
||||
dispatch('mediaError', 'Audio codec unsupported')
|
||||
}
|
||||
|
||||
dispatch('mediaSuccess')
|
||||
|
||||
const dimensions = {
|
||||
width: mediaElement.videoWidth,
|
||||
height: mediaElement.videoHeight
|
||||
}
|
||||
|
||||
// As soon as we know the video dimensions, resize the window
|
||||
dispatch('setDimensions', dimensions)
|
||||
}
|
||||
|
||||
// check if we can decode audio track
|
||||
if (state.playing.type === 'audio') {
|
||||
if (mediaElement.audioTracks.length === 0) {
|
||||
dispatch('mediaError', 'Audio codec unsupported')
|
||||
}
|
||||
|
||||
dispatch('mediaSuccess')
|
||||
}
|
||||
dispatch('setDimensions', dimensions)
|
||||
}
|
||||
|
||||
function onEnded (e) {
|
||||
@@ -168,20 +188,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) {
|
||||
|
||||
Reference in New Issue
Block a user