WebVTT captions on a Chromecast receiver as the default option

Trying to set up closed captions for chromecast using the default Chrome sender app but it's not working. The code is similar to the sample provided in the docs, seen here. I've shared a snippet that might be too sandboxed, view it on a normal html page: Click here!
First connect your Chromecast using the top button, then click "load video".

Snippet Code:

var suburl = 'https://cors-anywhere.herokuapp.com/brenopolanski.com/html5-video-webvtt-example/MIB2-subtitles-pt-BR.vtt';
var mediaurl = 'https://cors-anywhere.herokuapp.com/www.w3schools.com/html/mov_bbb.mp4';
var mediaInfo;
window['__onGCastApiAvailable'] = function(isAvailable) {
  if (isAvailable) {
    initializeCastApi();
  }
};
initializeCastApi = function() {
  cast.framework.CastContext.getInstance().setOptions({
    receiverApplicationId:
      chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID
  });
  var englishSubtitle = new chrome.cast.media.Track(1, // track ID
  chrome.cast.media.TrackType.TEXT);
  englishSubtitle.trackContentId = suburl;
  englishSubtitle.trackContentType = 'text/vtt';
  englishSubtitle.subtype = chrome.cast.media.TextTrackType.SUBTITLES;
  englishSubtitle.name = 'English Subtitles';
  englishSubtitle.language = 'en-US';
  englishSubtitle.customData = null;

  mediaInfo = new chrome.cast.media.MediaInfo(mediaurl);
  var textTrackStyle = new chrome.cast.media.TextTrackStyle();
  textTrackStyle.foregroundColor = '#80FF0000';

  mediaInfo.contentType = 'video/mp4';
  mediaInfo.metadata = new chrome.cast.media.GenericMediaMetadata();
  mediaInfo.customData = null;
  mediaInfo.streamType = chrome.cast.media.StreamType.BUFFERED;
  mediaInfo.textTrackStyle = textTrackStyle
  mediaInfo.duration = null;
  mediaInfo.tracks = [englishSubtitle];
  mediaInfo.activeTrackIds = [1];
};

function loadVideo() {
  var castSession = cast.framework.CastContext.getInstance().getCurrentSession();
  var request = new chrome.cast.media.LoadRequest(mediaInfo);
  castSession.loadMedia(request).then(
  function() { console.log('Load succeed'); },
  function(errorCode) { console.log('Error code: ' + errorCode); });
}
.cast-button, .load-button {
  max-width: 50px;
  max-height: 50px;
}
<!DOCTYPE html>
<html>
<head>
<title>Sample chromcast</title>
</head>
<body>
<div class="cast-button">
  <google-cast-launcher></google-cast-launcher>
</div>
<button class="load-button" onclick="loadVideo()"> Load video </button>

<script src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"></script>
</body>
</html>

Answer №1

Despite my extensive search efforts, I have not been able to locate the exact source of the problem. However, I came across a fantastic wrapper for the ChromeCast SDK that provides support for subtitles: https://github.com/Fenny/ChromecastJS/

You can also check out this demo:

I hope this information proves useful to someone else!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to properly direct to an internal page while utilizing [routerLink] and setting target="_blank" without triggering a full page reload?

I'm attempting to use [routerLink] along with target="_blank" to direct to an internal page without triggering a full app reload. Currently, the page opens in a new tab, but the whole application is refreshed. Here is the HTML: <a [routerLink]=" ...

The content within the iframe is not displayed

I've set up a dropdown menu with separate iframes for each option. Here's the code I used: $(function(){ $('#klanten-lijst').on('change',function(){ $('#klanten div').hide(); $('.klant-'+t ...

When I scroll and update my webpage, the navigation header tends to lose its distinct features. This issue can be resolved

When I scroll, my navigation header changes from being transparent to having a solid color, and this feature works perfectly. However, whenever I refresh the page while already halfway down, the properties of my navigation header are reset and it reverts ...

Is there a way to insert a value into the input field using JQuery or JavaScript?

After reading my previous post on posting values into an input box, a commenter suggested using JQuery or Javascript. For more code and information, please refer to the link provided above. <label>Date</label>:&nbsp&nbsp <input sty ...

How can we simplify this React component to reduce its verbosity?

After creating a test project to delve into react, react-router and react-redux, I revisited the Settings.jsx file. Now, I am pondering on how to streamline it and reduce potential errors. import React, { Component } from "react"; import { connect } from ...

Using Rxjs to reset an observable with combineLatest

My scenario involves 4 different observables being combined using "combineLatest". I am looking for a way to reset the value of observable 2 if observables 1, 3, or 4 emit a value. Is this possible? Thank you! Mat-table sort change event (Sort class) Mat- ...

Tips for successfully passing an array containing multiple values within the jsPDF body

I'm experimenting with jsPDF to showcase a list of products that users have ordered. I've managed to set up my columns and generate the PDF for download, but I'm facing some challenges with populating the body section. When attempting to sen ...

I am searching for a Nodejs library that has the ability to serialize and deserialize paths composed of named components, such as URL pathnames. Can

Here is an example: formatPath("/:item1/:item2/:item3", {item1: "apple", item2: "banana", item3: "cherry"}) => /apple/banana/cherry deserializePath("/:item1/:item2/:item3", "/apple/banana/cherry") => {item1: "apple", item2: "banana", item3: "cher ...

Verifying the Absence of Events in the Chosen Month Display of the FullCalendar jQuery Plugin

Currently utilizing full calendar, which is being shown in month view with toggle buttons for navigating between months. Now, I am looking to have a message appear that reads "No events scheduled for the month." if there are no event objects present for t ...

Understanding Vue.js - encountering the error message "property or method is not defined"

Recently, I've come across an issue that seems to be common among many people, but for some reason, I am unable to find a solution despite looking at similar questions. The problem arises when I use a v-for in a Vue Component and the array value cons ...

What is the best way to create height segments from a cylinder in three.js?

My current project involves a cylinder that is divided into multiple height segments, with the number of segments depending on the specific data. Each height segment contains a value that I want to use for extruding the entire circle at that particular hei ...

Incorporating a CSS stylesheet into the theme settings of the Stratus 2 Beta platform

I have been attempting to personalize my Stratus 2 Beta by implementing a custom theme. I created a separate CSS file named "stratus.css" and stored it in the CSS directory of my website - with the CSS code being identical to this example. Below is my Jav ...

How can one identify a concealed glitch that exclusively occurs for a particular individual or hardware in a React environment?

Is it possible to identify a bug that occurs only with a particular individual or hardware in a React application? This bug is invisible and never appears during tests, but only manifests with a specific client within my company. Do you have any tips on h ...

TypeScript interface with an optional parameter that is treated as a required parameter

Within my interface, I have a property that can be optional. In the constructor, I set default values for this property, which are then overridden by values passed in as the first parameter. If no properties are set, the defaults are used. I am looking fo ...

Is there a way to enlarge the font size for a complete tag?

I'm having trouble with a project. One of the tasks is to use jQuery or JavaScript to increase the font size of a paragraph. The console statements are incrementing by +1 with every mouse click (the first click adds 1, the second adds 2, and so on). ...

Stop users from repeating an action

We are encountering challenges with users repeating a specific action, even though we have measures in place to prevent it. Here is an overview of our current approach: Client side: The button becomes disabled after one click. Server side: We use a key h ...

Launch a new window for a div when a button is clicked

Hey everyone, I need some help with opening a div in a new window. Currently, I am using window.open and it is working fine. Here is the code snippet: <div id="pass">pass this to the new window</div> <a href="#" onclick="openWin()">clic ...

What is the process for implementing text box validation on a button click within a gridview in asp.net utilizing javascript?

How can I implement textbox blank validation on button click within a gridview using JavaScript? My gridview has multiple rows with 2 textboxes and a save button in each row. I need to validate the textboxes when their corresponding save button is clicked. ...

What is the best way to send a string from an HTML form, route it through a router, and create and save an object?

Currently, I am facing an issue while attempting to transfer a string from the frontend to the backend. The technologies I am using include Node, Express, Body Parser, EJS, and PostgreSQL. Here is the basic structure of my file system: – app |– api ...

Pondering in AngularJS - what is the best way to alter the DOM during an AJAX call?

I'm completely new to AngularJS and trying to transition from a jQuery background. After reading through "Thinking in AngularJS if I have a jQuery background?" on Stack Overflow, I understand the concept but am struggling to implement it without depen ...