Save video position

This commit is contained in:
DC
2016-05-20 23:57:50 -07:00
parent 8af4f42c42
commit ca7c872420
3 changed files with 23 additions and 7 deletions

View File

@@ -1025,6 +1025,15 @@ function openPlayerFromActiveTorrent (torrentSummary, index, timeout, cb) {
: TorrentPlayer.isAudio(fileSummary) ? 'audio'
: 'other'
// pick up where we left off
if (fileSummary.currentTime) {
var fraction = fileSummary.currentTime / fileSummary.duration
var secondsLeft = fileSummary.duration - fileSummary.currentTime
if (fraction < 0.9 && secondsLeft > 10) {
state.playing.jumpToTime = fileSummary.currentTime
}
}
// if it's audio, parse out the metadata (artist, title, etc)
if (state.playing.type === 'audio' && !fileSummary.audioInfo) {
ipcRenderer.send('wt-get-audio-metadata', torrentSummary.infoHash, index)

View File

@@ -9,8 +9,7 @@ var LocationHistory = require('./lib/location-history')
module.exports = {
getInitialState,
getDefaultPlayState,
getDefaultSavedState,
getPlayingTorrentSummary
getDefaultSavedState
}
function getInitialState () {
@@ -63,7 +62,8 @@ function getInitialState () {
/*
* Getters, for convenience
*/
getPlayingTorrentSummary
getPlayingTorrentSummary,
getPlayingFileSummary
}
}
@@ -276,3 +276,9 @@ function getPlayingTorrentSummary () {
var infoHash = this.playing.infoHash
return this.saved.torrents.find((x) => x.infoHash === infoHash)
}
function getPlayingFileSummary () {
var torrentSummary = this.getPlayingTorrentSummary()
if (!torrentSummary) return null
return torrentSummary.files[this.playing.fileIndex]
}

View File

@@ -63,8 +63,10 @@ function renderMedia (state) {
tracks[j].mode = (j === state.playing.subtitles.selectedIndex) ? 'showing' : 'hidden'
}
state.playing.currentTime = mediaElement.currentTime
state.playing.duration = mediaElement.duration
// Save video position
var file = state.getPlayingFileSummary()
file.currentTime = state.playing.currentTime = mediaElement.currentTime
file.duration = state.playing.duration = mediaElement.duration
state.playing.volume = mediaElement.volume
}
@@ -170,8 +172,7 @@ function renderOverlay (state) {
}
function renderAudioMetadata (state) {
var torrentSummary = state.getPlayingTorrentSummary()
var fileSummary = torrentSummary.files[state.playing.fileIndex]
var fileSummary = state.getPlayingFileSummary()
if (!fileSummary.audioInfo) return
var info = fileSummary.audioInfo