From 11f8e428a0ffcbafc7e598038b36c88fd26f0c22 Mon Sep 17 00:00:00 2001 From: Adam Gotlib Date: Sun, 4 Sep 2016 00:25:19 +0200 Subject: [PATCH] Restore playback state when reopening player (#877) --- src/renderer/controllers/playback-controller.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/renderer/controllers/playback-controller.js b/src/renderer/controllers/playback-controller.js index 8fe29ad0..bc7afe62 100644 --- a/src/renderer/controllers/playback-controller.js +++ b/src/renderer/controllers/playback-controller.js @@ -34,12 +34,20 @@ module.exports = class PlaybackController { else this.play() }) } else { + let initialized = false state.location.go({ url: 'player', setup: (cb) => { - this.play() + const torrentSummary = TorrentSummary.getByKey(state, infoHash) + + if (index === undefined || initialized) index = torrentSummary.mostRecentFileIndex + if (index === undefined) index = torrentSummary.files.findIndex(TorrentPlayer.isPlayable) + if (index === undefined) return cb(new errors.UnplayableError()) + + initialized = true + this.openPlayer(infoHash, index, (err) => { - if (!err) this.play + if (!err) this.play() cb(err) }) }, @@ -211,10 +219,6 @@ module.exports = class PlaybackController { const state = this.state const torrentSummary = TorrentSummary.getByKey(state, infoHash) - if (index === undefined) index = torrentSummary.mostRecentFileIndex - if (index === undefined) index = torrentSummary.files.findIndex(TorrentPlayer.isPlayable) - if (index === undefined) return cb(new errors.UnplayableError()) - state.playing.infoHash = torrentSummary.infoHash // update UI to show pending playback