Chromecast custom media receiver

I want to show a webpage using Chromecast. The page is currently very simple (just β€œHello World!”), But I hope to make it more complex and possibly interactive with a second screen. However, I found that if I do not create a media manager ( new cast.receiver.MediaManager(window.mediaElement)), the session immediately expires on my sender (called function sessionUpdateListener(false)). The page is still displayed, but I can no longer interact with it, including stopping the application.

I wonder if this is a design mistake, or am I doing something wrong?

Here is the code for my recipient ...

<html>
<head>
    <title>Hello World Chromecast App</title>
    <style type="text/css">
        *
        {
            color: white;
        }
    </style>
</head>
<body>
    <div>Hello World!</div>

    <script src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
    <script type="text/javascript">
        window.onload = function () {
            window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
            window.castReceiverManager.start();
        }
    </script>
</body>
</html>
+4
source share
3 answers

, start . , .

<script type="text/javascript">
    (function () {
        var mgr;
        var bus;

        window.onload = function () {
            mgr = cast.receiver.CastReceiverManager.getInstance();
            bus = mgr.getCastMessageBus('urn:x-cast:com.sample.hello');
            mgr.start();
        }
    })();
</script>
+2

. :

1) -.

window.mediaElement = document.getElementById('receiverVideoElement');
window.mediaManager = new cast.receiver.MediaManager(window.mediaElement);

...

2) .

// create a CastMessageBus to handle messages for a custom namespace
window.messageBus =
  window.castReceiverManager.getCastMessageBus(
    'urn:x-cast:com.google.cast.sample.firework');

. , - , .

+1

( ), .

MediaManager, , (LOAD, PLAY, PAUSE...), . MediaManager CastMessageBus .

, CastMessageBus, CastChannel.

- ( ), .

TicTacToe. , CastMessageBus JSON:

TicTacToe.PROTOCOL = 'urn: x-cast: com.google.cast.demo.tictactoe'; this.castMessageBus_ = this.castReceiverManager_.getCastMessageBus (TicTacToe.PROTOCOL, cast.receiver.CastMessageBus.MessageType.JSON);

A protocol is simply a unique line starting with "urn: x-cast:", which you can define and must use the receiver and sender to identify the protocol.

+1
source

Source: https://habr.com/ru/post/1532592/


All Articles