mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Update chromecast with new data model
This commit is contained in:
parent
8df05896b5
commit
99e2ea228d
@ -9,7 +9,7 @@ export default class CastPlayer extends EventEmitter {
|
||||
this.player = null
|
||||
this.playerController = null
|
||||
|
||||
this.audiobook = null
|
||||
this.libraryItem = null
|
||||
this.audioTracks = []
|
||||
this.currentTrackIndex = 0
|
||||
this.isHlsTranscode = null
|
||||
@ -70,22 +70,22 @@ export default class CastPlayer extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
async set(audiobook, tracks, isHlsTranscode, startTime, playWhenReady = false) {
|
||||
this.audiobook = audiobook
|
||||
async set(libraryItem, tracks, isHlsTranscode, startTime, playWhenReady = false) {
|
||||
this.libraryItem = libraryItem
|
||||
this.audioTracks = tracks
|
||||
this.isHlsTranscode = isHlsTranscode
|
||||
this.playWhenReady = playWhenReady
|
||||
|
||||
this.currentTime = startTime
|
||||
|
||||
var coverImg = this.ctx.$store.getters['globals/getLibraryItemCoverSrc'](audiobook)
|
||||
var coverImg = this.ctx.$store.getters['globals/getLibraryItemCoverSrc'](libraryItem)
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
this.coverUrl = coverImg
|
||||
} else {
|
||||
this.coverUrl = `${window.location.origin}${coverImg}`
|
||||
}
|
||||
|
||||
var request = buildCastLoadRequest(this.audiobook, this.coverUrl, this.audioTracks, this.currentTime, playWhenReady, this.defaultPlaybackRate)
|
||||
var request = buildCastLoadRequest(this.libraryItem, this.coverUrl, this.audioTracks, this.currentTime, playWhenReady, this.defaultPlaybackRate)
|
||||
|
||||
var castSession = cast.framework.CastContext.getInstance().getCurrentSession()
|
||||
await castLoadMedia(castSession, request)
|
||||
@ -126,7 +126,7 @@ export default class CastPlayer extends EventEmitter {
|
||||
if (!this.player) return
|
||||
if (time < this.currentTrack.startOffset || time > this.currentTrack.startOffset + this.currentTrack.duration) {
|
||||
// Change Track
|
||||
var request = buildCastLoadRequest(this.audiobook, this.coverUrl, this.audioTracks, time, playWhenReady, this.defaultPlaybackRate)
|
||||
var request = buildCastLoadRequest(this.libraryItem, this.coverUrl, this.audioTracks, time, playWhenReady, this.defaultPlaybackRate)
|
||||
var castSession = cast.framework.CastContext.getInstance().getCurrentSession()
|
||||
await castLoadMedia(castSession, request)
|
||||
} else {
|
||||
|
@ -1,13 +1,13 @@
|
||||
|
||||
function getMediaInfoFromTrack(audiobook, castImage, track) {
|
||||
function getMediaInfoFromTrack(libraryItem, castImage, track) {
|
||||
// https://developers.google.com/cast/docs/reference/web_sender/chrome.cast.media.AudiobookChapterMediaMetadata
|
||||
var metadata = new chrome.cast.media.AudiobookChapterMediaMetadata()
|
||||
metadata.bookTitle = audiobook.book.title
|
||||
metadata.bookTitle = libraryItem.media.metadata.title
|
||||
metadata.chapterNumber = track.index
|
||||
metadata.chapterTitle = track.title
|
||||
metadata.images = [castImage]
|
||||
metadata.title = track.title
|
||||
metadata.subtitle = audiobook.book.title
|
||||
metadata.subtitle = libraryItem.media.metadata.title
|
||||
|
||||
var trackurl = track.fullContentUrl
|
||||
var mimeType = track.mimeType
|
||||
@ -18,18 +18,19 @@ function getMediaInfoFromTrack(audiobook, castImage, track) {
|
||||
return mediainfo
|
||||
}
|
||||
|
||||
function buildCastMediaInfo(audiobook, coverUrl, tracks) {
|
||||
function buildCastMediaInfo(libraryItem, coverUrl, tracks) {
|
||||
const castImage = new chrome.cast.Image(coverUrl)
|
||||
return tracks.map(t => getMediaInfoFromTrack(audiobook, castImage, t))
|
||||
return tracks.map(t => getMediaInfoFromTrack(libraryItem, castImage, t))
|
||||
}
|
||||
|
||||
function buildCastQueueRequest(audiobook, coverUrl, tracks, startTime) {
|
||||
var mediaInfoItems = buildCastMediaInfo(audiobook, coverUrl, tracks)
|
||||
function buildCastQueueRequest(libraryItem, coverUrl, tracks, startTime) {
|
||||
var mediaInfoItems = buildCastMediaInfo(libraryItem, coverUrl, tracks)
|
||||
|
||||
var containerMetadata = new chrome.cast.media.AudiobookContainerMetadata()
|
||||
containerMetadata.authors = [audiobook.book.authorFL]
|
||||
containerMetadata.narrators = [audiobook.book.narratorFL]
|
||||
containerMetadata.publisher = audiobook.book.publisher || undefined
|
||||
containerMetadata.authors = libraryItem.media.metadata.authors.map(a => a.name)
|
||||
containerMetadata.narrators = libraryItem.media.metadata.narrators || []
|
||||
containerMetadata.publisher = libraryItem.media.metadata.publisher || undefined
|
||||
containerMetadata.title = libraryItem.media.metadata.title
|
||||
|
||||
var mediaQueueItems = mediaInfoItems.map((mi) => {
|
||||
var queueItem = new chrome.cast.media.QueueItem(mi)
|
||||
@ -41,7 +42,7 @@ function buildCastQueueRequest(audiobook, coverUrl, tracks, startTime) {
|
||||
var trackStartIndex = track ? track.index - 1 : 0
|
||||
var trackStartTime = Math.floor(track ? startTime - track.startOffset : 0)
|
||||
|
||||
var queueData = new chrome.cast.media.QueueData(audiobook.id, audiobook.book.title, '', false, mediaQueueItems, trackStartIndex, trackStartTime)
|
||||
var queueData = new chrome.cast.media.QueueData(libraryItem.id, libraryItem.media.metadata.title, '', false, mediaQueueItems, trackStartIndex, trackStartTime)
|
||||
queueData.containerMetadata = containerMetadata
|
||||
queueData.queueType = chrome.cast.media.QueueType.AUDIOBOOK
|
||||
return queueData
|
||||
@ -57,10 +58,10 @@ function castLoadMedia(castSession, request) {
|
||||
})
|
||||
}
|
||||
|
||||
function buildCastLoadRequest(audiobook, coverUrl, tracks, startTime, autoplay, playbackRate) {
|
||||
function buildCastLoadRequest(libraryItem, coverUrl, tracks, startTime, autoplay, playbackRate) {
|
||||
var request = new chrome.cast.media.LoadRequest()
|
||||
|
||||
request.queueData = buildCastQueueRequest(audiobook, coverUrl, tracks, startTime)
|
||||
request.queueData = buildCastQueueRequest(libraryItem, coverUrl, tracks, startTime)
|
||||
request.currentTime = request.queueData.startTime
|
||||
|
||||
request.autoplay = autoplay
|
||||
|
@ -2,8 +2,8 @@ export default (ctx) => {
|
||||
var sendInit = async (castContext) => {
|
||||
// Fetch background covers for chromecast (temp)
|
||||
var covers = await ctx.$axios.$get(`/api/libraries/${ctx.$store.state.libraries.currentLibraryId}/items?limit=40&minified=1`).then((data) => {
|
||||
return data.results.filter((b) => b.book.cover).map((ab) => {
|
||||
var coverUrl = ctx.$store.getters['globals/getLibraryItemCoverSrc'](ab)
|
||||
return data.results.filter((b) => b.media.coverPath).map((libraryItem) => {
|
||||
var coverUrl = ctx.$store.getters['globals/getLibraryItemCoverSrc'](libraryItem)
|
||||
if (process.env.NODE_ENV === 'development') return coverUrl
|
||||
return `${window.location.origin}${coverUrl}`
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user