Casting requires a receiver-readable URL that the device can fetch directly. URLs like blob:, data:, file:, mediastream:, or localhost will not work.
To ensure compatibility, especially for signed or extensionless URLs, you should provide an explicit contentType or use the preProcessUrl hook to resolve a network-accessible URL.
Recommended Patterns
1. Using preProcessUrl (Best for signed/rewritten URLs):
const player = new Player({
id,
url: 'https://cdn.example.com/play?id=main',
contentType: 'application/x-mpegURL',
preProcessUrl(url, ext) {
if (ext?.scene === 'cast' && ext?.protocol === 'chromecast') {
return {
url: signForReceiver(url),
contentType: 'application/x-mpegURL'
}
}
return { url }
},
plugins: [CastPlugin],
cast: { chromecast: true }
})
2. Using definition.list:
const player = new Player({
id,
definition: {
list: [
{
definition: '720p',
url: 'https://cdn.example.com/play?id=720',
contentType: 'application/x-mpegURL'
}
]
},
plugins: [CastPlugin],
cast: { chromecast: true }
})
3. Using source-array form:
const player = new Player({
id,
url: [
{
src: 'https://cdn.example.com/play?id=main',
type: 'application/x-mpegURL'
}
],
plugins: [CastPlugin],
cast: { chromecast: true }
})
// Recommended for definition lists
const player = new Player({
id,
definition: {
list: [
{
definition: '720p',
url: 'https://cdn.example.com/play?id=720',
contentType: 'application/x-mpegURL'
}
]
},
plugins: [CastPlugin],
cast: { chromecast: true }
})
// Recommended when the business layer signs or rewrites URLs
const player = new Player({
id,
url: 'https://cdn.example.com/play?id=main',
contentType: 'application/x-mpegURL',
preProcessUrl(url, ext) {
if (ext?.scene === 'cast' && ext?.protocol === 'chromecast') {
return {
url: signForReceiver(url),
contentType: 'application/x-mpegURL'
}
}
return { url }
},
plugins: [CastPlugin],
cast: { chromecast: true }
})
// Source-array form is also supported
const player = new Player({
id,
url: [
{
src: 'https://cdn.example.com/play?id=main',
type: 'application/x-mpegURL'
}
],
plugins: [CastPlugin],
cast: { chromecast: true }
})