use videoTracks and audioTracks to check unsupported codecs
This commit is contained in:
@@ -25,7 +25,8 @@ function init () {
|
|||||||
title: 'About ' + config.APP_WINDOW_TITLE,
|
title: 'About ' + config.APP_WINDOW_TITLE,
|
||||||
useContentSize: true,
|
useContentSize: true,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: true
|
nodeIntegration: true,
|
||||||
|
enableBlinkFeatures: 'AudioVideoTracks'
|
||||||
},
|
},
|
||||||
width: 300
|
width: 300
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ function init (state, options) {
|
|||||||
useContentSize: true, // Specify web page size without OS chrome
|
useContentSize: true, // Specify web page size without OS chrome
|
||||||
width: initialBounds.width,
|
width: initialBounds.width,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: true
|
nodeIntegration: true,
|
||||||
|
enableBlinkFeatures: 'AudioVideoTracks'
|
||||||
},
|
},
|
||||||
x: initialBounds.x,
|
x: initialBounds.x,
|
||||||
y: initialBounds.y
|
y: initialBounds.y
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ function init () {
|
|||||||
title: 'webtorrent-hidden-window',
|
title: 'webtorrent-hidden-window',
|
||||||
useContentSize: true,
|
useContentSize: true,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nodeIntegration: true
|
nodeIntegration: true,
|
||||||
|
enableBlinkFeatures: 'AudioVideoTracks'
|
||||||
},
|
},
|
||||||
width: 150
|
width: 150
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -54,13 +54,6 @@ 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'),
|
|
||||||
(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
|
// When the user clicks or drags on the progress bar, jump to that position
|
||||||
if (state.playing.jumpToTime != null) {
|
if (state.playing.jumpToTime != null) {
|
||||||
@@ -132,6 +125,7 @@ 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')}
|
||||||
>
|
>
|
||||||
@@ -151,15 +145,38 @@ function renderMedia (state) {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
// As soon as we know the video dimensions, resize the window
|
|
||||||
function onLoadedMetadata (e) {
|
function onLoadedMetadata (e) {
|
||||||
if (state.playing.type !== 'video') return
|
const mediaElement = e.target
|
||||||
const video = e.target
|
|
||||||
const dimensions = {
|
// check if we can decode video and audio track
|
||||||
width: video.videoWidth,
|
if (state.playing.type === 'video') {
|
||||||
height: video.videoHeight
|
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) {
|
function onEnded (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user