Show error when media format is unsupported (#409)
* fix error about pop * location-history: add optional callbacks * set handler on first tick discovered by @dcposch * Show error when media format is unsupported Before this change, the player would just get stuck on the loading screen forever without notifying the user.
This commit is contained in:
@@ -285,6 +285,11 @@ function dispatch (action, ...args) {
|
|||||||
if (action === 'mediaStalled') {
|
if (action === 'mediaStalled') {
|
||||||
state.playing.isStalled = true
|
state.playing.isStalled = true
|
||||||
}
|
}
|
||||||
|
if (action === 'mediaError') {
|
||||||
|
state.location.back(function () {
|
||||||
|
onError(new Error('Unsupported file format'))
|
||||||
|
})
|
||||||
|
}
|
||||||
if (action === 'mediaTimeUpdate') {
|
if (action === 'mediaTimeUpdate') {
|
||||||
state.playing.lastTimeUpdate = new Date().getTime()
|
state.playing.lastTimeUpdate = new Date().getTime()
|
||||||
state.playing.isStalled = false
|
state.playing.isStalled = false
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ function dispatcher (...args) {
|
|||||||
var json = JSON.stringify(args)
|
var json = JSON.stringify(args)
|
||||||
var handler = _dispatchers[json]
|
var handler = _dispatchers[json]
|
||||||
if (!handler) {
|
if (!handler) {
|
||||||
_dispatchers[json] = (e) => {
|
handler = _dispatchers[json] = (e) => {
|
||||||
// Don't click on whatever is below the button
|
// Don't click on whatever is below the button
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
// Don't regisiter clicks on disabled buttons
|
// Don't regisiter clicks on disabled buttons
|
||||||
|
|||||||
@@ -7,28 +7,30 @@ function LocationHistory () {
|
|||||||
this._pending = null
|
this._pending = null
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationHistory.prototype.go = function (page) {
|
LocationHistory.prototype.go = function (page, cb) {
|
||||||
console.log('go', page)
|
console.log('go', page)
|
||||||
this.clearForward()
|
this.clearForward()
|
||||||
this._go(page)
|
this._go(page, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationHistory.prototype._go = function (page) {
|
LocationHistory.prototype._go = function (page, cb) {
|
||||||
if (this._pending) return
|
if (this._pending) return
|
||||||
if (page.onbeforeload) {
|
if (page.onbeforeload) {
|
||||||
this._pending = page
|
this._pending = page
|
||||||
page.onbeforeload((err) => {
|
page.onbeforeload((err) => {
|
||||||
if (this._pending !== page) return /* navigation was cancelled */
|
if (this._pending !== page) return /* navigation was cancelled */
|
||||||
this._pending = null
|
this._pending = null
|
||||||
if (err) return
|
if (err) return cb(err)
|
||||||
this._history.push(page)
|
this._history.push(page)
|
||||||
|
if (cb) cb()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this._history.push(page)
|
this._history.push(page)
|
||||||
|
if (cb) cb()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationHistory.prototype.back = function () {
|
LocationHistory.prototype.back = function (cb) {
|
||||||
if (this._history.length <= 1) return
|
if (this._history.length <= 1) return
|
||||||
|
|
||||||
var page = this._history.pop()
|
var page = this._history.pop()
|
||||||
@@ -39,17 +41,19 @@ LocationHistory.prototype.back = function () {
|
|||||||
// call finishes first.
|
// call finishes first.
|
||||||
page.onbeforeunload(() => {
|
page.onbeforeunload(() => {
|
||||||
this._forward.push(page)
|
this._forward.push(page)
|
||||||
|
if (cb) cb()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this._forward.push(page)
|
this._forward.push(page)
|
||||||
|
if (cb) cb()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationHistory.prototype.forward = function () {
|
LocationHistory.prototype.forward = function (cb) {
|
||||||
if (this._forward.length === 0) return
|
if (this._forward.length === 0) return
|
||||||
|
|
||||||
var page = this._forward.pop()
|
var page = this._forward.pop()
|
||||||
this._go(page)
|
this._go(page, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
LocationHistory.prototype.clearForward = function () {
|
LocationHistory.prototype.clearForward = function () {
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ var sounds = {
|
|||||||
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'error.wav'),
|
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'error.wav'),
|
||||||
volume: 0.2
|
volume: 0.2
|
||||||
},
|
},
|
||||||
POP: {
|
|
||||||
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'pop.wav'),
|
|
||||||
volume: 0.2
|
|
||||||
},
|
|
||||||
PLAY: {
|
PLAY: {
|
||||||
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'play.wav'),
|
url: 'file://' + path.join(config.STATIC_PATH, 'sound', 'play.wav'),
|
||||||
volume: 0.2
|
volume: 0.2
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ function renderMedia (state) {
|
|||||||
onplay=${dispatcher('mediaPlaying')}
|
onplay=${dispatcher('mediaPlaying')}
|
||||||
onpause=${dispatcher('mediaPaused')}
|
onpause=${dispatcher('mediaPaused')}
|
||||||
onstalling=${dispatcher('mediaStalled')}
|
onstalling=${dispatcher('mediaStalled')}
|
||||||
|
onerror=${dispatcher('mediaError')}
|
||||||
ontimeupdate=${dispatcher('mediaTimeUpdate')}
|
ontimeupdate=${dispatcher('mediaTimeUpdate')}
|
||||||
autoplay>
|
autoplay>
|
||||||
${trackTags}
|
${trackTags}
|
||||||
|
|||||||
Reference in New Issue
Block a user