6

I cast URLs to my Chromecast to display web pages on it, and this generally works fine, the pages run scripts, css and images.

However I've not been able to play audio in those web pages. When I cast something like YouTube to the Chromecast that audio does play as expected.

I've tried playing audio using:

new Audio('/audioFile.mp3').play();

and

<audio id="audio" src="/audioFile.mp3" />
<script>document.getElementById('audio').play()</script>

Both work in my desktop browser, but not when casting a URL to the Chromecast.

Is there a supported method of playing audio on the Chromecast's browser?

Note: I'm not streaming a browser tab to the Chromecast, I'm directly casting the URL and it is rendering on the Chromecast device and not on any other devices

Jane Panda
  • 1,591
  • 4
  • 23
  • 51

2 Answers2

1

I tested the new Audio(...).play() in my chromeCast and it worked. The audio was reproduced on my TV. This is the demo that worked:

window.onclick = function () {
  new Audio('https://ia802508.us.archive.org/5/items/testmp3testfile/mpthreetest.mp3').play();
};

Try it out: https://codepen.io/rafaelcastrocouto/pen/xJMPBv

Are you waiting for user input? Because Chrome will not start audio without it anymore, it will throw an error:

Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first. Read more https://developers.google.com/web/updates/2017/09/autoplay-policy-changes

rafaelcastrocouto
  • 11,781
  • 3
  • 38
  • 63
  • 2
    How do you interact (user input) with a URL that has been cast and rendered only on the Chromecast? – Jane Panda Aug 11 '18 at 16:41
  • I really don't think that's possible ... seems you can only interact with the screen if it has been cast by a desktop chrome. Try muting the audio but it's a long shot https://stackoverflow.com/questions/49930680/how-to-handle-uncaught-in-promise-domexception-play-failed-because-the-use – rafaelcastrocouto Aug 11 '18 at 17:47
0

Please read Google Chromecast Support answer:

Or use this extension for Chrome to cast any video, radio, audio, image given its URL to Chromecast.

I hope it helps you.

Bharata
  • 13,509
  • 6
  • 36
  • 50
  • The symbols are just there as placeholders for the actual URL, I'll update the question to clarify that. Also I'm not having any issues casting the page, the page renders fine with the exception of playing audio. – Jane Panda Aug 09 '18 at 17:38
  • @JanePanda, OK, I deleted the first part from my answer too. Please read my updated answer (second part) and write feedback. – Bharata Aug 09 '18 at 17:44
  • 1
    Thanks, but I'm not having an issue casting, it's when a web page URL is being cast & rendered on the Chromecast and that web page tries to play an audio file that fails. I cannot simply cast an audio file because that would override the web page URL – Jane Panda Aug 09 '18 at 19:54
  • @JanePanda, and did you tried it with extension for Chrome (see second link in my answer)? – Bharata Aug 09 '18 at 20:00
  • Casting using the extension causes the same issue. – Jane Panda Aug 10 '18 at 02:05