@@ -712,16 +712,21 @@ function startServerFromReadyTorrent (torrent, index, cb) {
|
||||
// update state
|
||||
state.playing.infoHash = torrent.infoHash
|
||||
state.playing.fileIndex = index
|
||||
state.playing.type = TorrentPlayer.isVideo(file) ? 'video' : 'audio'
|
||||
state.playing.audioInfo = null
|
||||
state.playing.type = TorrentPlayer.isVideo(file) ? 'video'
|
||||
: TorrentPlayer.isAudio(file) ? 'audio'
|
||||
: 'other'
|
||||
|
||||
// if it's audio, parse out the metadata (artist, title, etc)
|
||||
musicmetadata(file.createReadStream(), function (err, info) {
|
||||
if (err) return
|
||||
console.log('got audio metadata for %s: %v', file.name, info)
|
||||
state.playing.audioInfo = info
|
||||
update()
|
||||
})
|
||||
var torrentSummary = getTorrentSummary(torrent.infoHash)
|
||||
var fileSummary = torrentSummary.files[index]
|
||||
if (state.playing.type === 'audio' && !fileSummary.audioInfo) {
|
||||
musicmetadata(file.createReadStream(), function (err, info) {
|
||||
if (err) return
|
||||
console.log('got audio metadata for %s: %o', file.name, info)
|
||||
fileSummary.audioInfo = info
|
||||
update()
|
||||
})
|
||||
}
|
||||
|
||||
// either way, start a streaming torrent-to-http server
|
||||
var server = torrent.createServer()
|
||||
@@ -777,6 +782,7 @@ function openPlayer (infoHash, index, cb) {
|
||||
|
||||
var timeout = setTimeout(function () {
|
||||
torrentSummary.playStatus = 'timeout' /* no seeders available? */
|
||||
state.navigation.clearPending()
|
||||
playInterfaceSound('ERROR')
|
||||
update()
|
||||
}, 10000) /* give it a few seconds */
|
||||
|
||||
@@ -19,6 +19,7 @@ LocationHistory.prototype._go = function (page) {
|
||||
this._pending = page
|
||||
page.onbeforeload((err) => {
|
||||
if (err) return
|
||||
if (this._pending !== page) return /* navigation was cancelled */
|
||||
this._pending = null
|
||||
this._history.push(page)
|
||||
})
|
||||
@@ -67,3 +68,7 @@ LocationHistory.prototype.hasForward = function () {
|
||||
LocationHistory.prototype.pending = function () {
|
||||
return this._pending
|
||||
}
|
||||
|
||||
LocationHistory.prototype.clearPending = function () {
|
||||
this._pending = null
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ module.exports = {
|
||||
infoHash: null, /* the info hash of the torrent we're playing */
|
||||
fileIndex: null, /* the zero-based index within the torrent */
|
||||
location: 'local', /* 'local', 'chromecast', 'airplay' */
|
||||
type: null, /* 'audio' or 'video' */
|
||||
type: null, /* 'audio' or 'video', could be 'other' if ever support eg streaming to VLC */
|
||||
currentTime: 0, /* seconds */
|
||||
duration: 1, /* seconds */
|
||||
isPaused: true,
|
||||
@@ -32,7 +32,6 @@ module.exports = {
|
||||
lastTimeUpdate: 0, /* Unix time in ms */
|
||||
mouseStationarySince: 0 /* Unix time in ms */
|
||||
},
|
||||
audioInfo: null, /* set whenever an audio file is playing */
|
||||
pendingTorrents: {}, /* infohash to WebTorrent handle */
|
||||
devices: { /* playback devices like Chromecast and AppleTV */
|
||||
airplay: null, /* airplay client. finds and manages AppleTVs */
|
||||
|
||||
@@ -122,14 +122,15 @@ function renderOverlay (state) {
|
||||
}
|
||||
|
||||
function renderAudioMetadata (state) {
|
||||
if (!state.playing.audioInfo) return
|
||||
var info = state.playing.audioInfo
|
||||
var torrentSummary = getPlayingTorrentSummary(state)
|
||||
var fileSummary = torrentSummary.files[state.playing.fileIndex]
|
||||
if (!fileSummary.audioInfo) return
|
||||
var info = fileSummary.audioInfo
|
||||
|
||||
// Get audio track info
|
||||
var title = info.title
|
||||
if (!title) {
|
||||
var torrentSummary = getPlayingTorrentSummary(state)
|
||||
title = torrentSummary.files[state.playing.fileIndex].name
|
||||
title = fileSummary.name
|
||||
}
|
||||
var artist = info.artist && info.artist[0]
|
||||
var album = info.album
|
||||
|
||||
Reference in New Issue
Block a user