From 5023651e63110d40f52dadac79f1732248140fdf Mon Sep 17 00:00:00 2001 From: hicom150 Date: Wed, 25 Sep 2019 22:23:35 +0200 Subject: [PATCH 1/5] Improve codec unsupported detection --- src/renderer/pages/player-page.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/renderer/pages/player-page.js b/src/renderer/pages/player-page.js index 43f610d6..5d6fa37d 100644 --- a/src/renderer/pages/player-page.js +++ b/src/renderer/pages/player-page.js @@ -1,5 +1,3 @@ -/* global HTMLMediaElement */ - const React = require('react') const Bitfield = require('bitfield') const prettyBytes = require('prettier-bytes') @@ -56,6 +54,14 @@ function renderMedia (state) { mediaElement.pause() } else if (!state.playing.isPaused && mediaElement.paused) { 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 if (state.playing.jumpToTime != null) { @@ -127,10 +133,8 @@ function renderMedia (state) { onLoadedMetadata={onLoadedMetadata} onEnded={onEnded} onStalled={dispatcher('mediaStalled')} - onError={dispatcher('mediaError')} onTimeUpdate={dispatcher('mediaTimeUpdate')} onEncrypted={dispatcher('mediaEncrypted')} - onCanPlay={onCanPlay} > {trackTags} @@ -168,20 +172,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) { From d4a8d9a1200d793dae43557ab647d5d800c714a0 Mon Sep 17 00:00:00 2001 From: hicom150 Date: Mon, 7 Oct 2019 17:54:36 +0200 Subject: [PATCH 2/5] Apply review changes --- src/renderer/pages/player-page.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/renderer/pages/player-page.js b/src/renderer/pages/player-page.js index 5d6fa37d..8dc39f2f 100644 --- a/src/renderer/pages/player-page.js +++ b/src/renderer/pages/player-page.js @@ -54,14 +54,10 @@ function renderMedia (state) { mediaElement.pause() } else if (!state.playing.isPaused && mediaElement.paused) { mediaElement.play() - .then(() => { - dispatch('mediaSuccess') - }) - .catch((err) => { - if (err.name === 'NotSupportedError') { - dispatch('mediaError', 'Codec unsupported') - } - }) + .then( + () => dispatch('mediaSuccess'), + () => dispatch('mediaError', 'Codec unsupported') + ) } // When the user clicks or drags on the progress bar, jump to that position if (state.playing.jumpToTime != null) { From 3d85803df99ea5da6d5551d8be28a6d2c870d841 Mon Sep 17 00:00:00 2001 From: hicom150 Date: Wed, 25 Sep 2019 22:23:35 +0200 Subject: [PATCH 3/5] Improve codec unsupported detection --- src/renderer/pages/player-page.js | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/renderer/pages/player-page.js b/src/renderer/pages/player-page.js index 43f610d6..5d6fa37d 100644 --- a/src/renderer/pages/player-page.js +++ b/src/renderer/pages/player-page.js @@ -1,5 +1,3 @@ -/* global HTMLMediaElement */ - const React = require('react') const Bitfield = require('bitfield') const prettyBytes = require('prettier-bytes') @@ -56,6 +54,14 @@ function renderMedia (state) { mediaElement.pause() } else if (!state.playing.isPaused && mediaElement.paused) { 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 if (state.playing.jumpToTime != null) { @@ -127,10 +133,8 @@ function renderMedia (state) { onLoadedMetadata={onLoadedMetadata} onEnded={onEnded} onStalled={dispatcher('mediaStalled')} - onError={dispatcher('mediaError')} onTimeUpdate={dispatcher('mediaTimeUpdate')} onEncrypted={dispatcher('mediaEncrypted')} - onCanPlay={onCanPlay} > {trackTags} @@ -168,20 +172,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) { From f5e186dc67069eec8d9d1f96af72015d7c3de13a Mon Sep 17 00:00:00 2001 From: hicom150 Date: Mon, 7 Oct 2019 17:54:36 +0200 Subject: [PATCH 4/5] Apply review changes --- src/renderer/pages/player-page.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/renderer/pages/player-page.js b/src/renderer/pages/player-page.js index 5d6fa37d..a087b3b9 100644 --- a/src/renderer/pages/player-page.js +++ b/src/renderer/pages/player-page.js @@ -54,14 +54,13 @@ function renderMedia (state) { mediaElement.pause() } else if (!state.playing.isPaused && mediaElement.paused) { mediaElement.play() - .then(() => { - dispatch('mediaSuccess') - }) - .catch((err) => { - if (err.name === 'NotSupportedError') { + .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) { From f2c531baa4c20a531b5133f564e7be3f6c8f9e50 Mon Sep 17 00:00:00 2001 From: hicom150 Date: Sat, 12 Oct 2019 17:44:13 +0200 Subject: [PATCH 5/5] use videoTracks and audioTracks to check unsupported codecs --- src/main/windows/about.js | 3 ++- src/main/windows/main.js | 3 ++- src/main/windows/webtorrent.js | 3 ++- src/renderer/pages/player-page.js | 45 +++++++++++++++++++++---------- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/main/windows/about.js b/src/main/windows/about.js index fc16d517..1e6d6dc5 100644 --- a/src/main/windows/about.js +++ b/src/main/windows/about.js @@ -25,7 +25,8 @@ function init () { title: 'About ' + config.APP_WINDOW_TITLE, useContentSize: true, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + enableBlinkFeatures: 'AudioVideoTracks' }, width: 300 }) diff --git a/src/main/windows/main.js b/src/main/windows/main.js index dbfb7d0c..11aad3d0 100644 --- a/src/main/windows/main.js +++ b/src/main/windows/main.js @@ -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 diff --git a/src/main/windows/webtorrent.js b/src/main/windows/webtorrent.js index 8c58043b..cd08e225 100644 --- a/src/main/windows/webtorrent.js +++ b/src/main/windows/webtorrent.js @@ -26,7 +26,8 @@ function init () { title: 'webtorrent-hidden-window', useContentSize: true, webPreferences: { - nodeIntegration: true + nodeIntegration: true, + enableBlinkFeatures: 'AudioVideoTracks' }, width: 150 }) diff --git a/src/renderer/pages/player-page.js b/src/renderer/pages/player-page.js index a087b3b9..b9998d13 100644 --- a/src/renderer/pages/player-page.js +++ b/src/renderer/pages/player-page.js @@ -54,13 +54,6 @@ 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) { @@ -132,6 +125,7 @@ function renderMedia (state) { onLoadedMetadata={onLoadedMetadata} onEnded={onEnded} onStalled={dispatcher('mediaStalled')} + onError={dispatcher('mediaError')} onTimeUpdate={dispatcher('mediaTimeUpdate')} onEncrypted={dispatcher('mediaEncrypted')} > @@ -151,15 +145,38 @@ function renderMedia (state) { ) - // 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) {