Cast Cast User Timers

Using the Google CAF Receiver SDK , how do we prevent the receiver from timeout and automatically kill the casting session when we are not using the receiver player?

A standard use case for Google Cast is to send media files from the device to the destination receiver, and the receiver transfers the media player using the player. The CAF SDK receiver provides this functionality in a beautiful, simple way using an element cast-media-player .

But for those cases when we want to display from the device and display content where it is not related to use cast-media-player(for example, the HTML toolbar), how do we keep the receiver alive?

The following user-defined receiver, for example (HAML for short), causes the casting session to automatically end after 5 minutes ...

!!! 5
%html
  %head
    :css
      cast-media-player {
        display: none;
      }

    = javascript_include_tag 'https://www.gstatic.com/cast/sdk/libs/caf_receiver/v3/cast_receiver_framework.js'
  %body
    %cast-media-player

    :javascript
      const context = cast.framework.CastReceiverContext.getInstance();
      const player = context.getPlayerManager();

      player.setMessageInterceptor(cast.framework.messages.MessageType.LOAD, loadRequestData => {
        ...[load custom view]...
        return false;
      });

      context.start();

The receiver log shows the line cast.framework.common.IdleTimeoutManager] timer expiredand then turns off. An example of a log file is shown here .

I tried:

  • Increase cast.framework.CastReceiverOptions # maxInactivity to a very large number
  • Periodically downloading new data from the sender
  • Periodically sending user messages from recipient to sender
  • Periodically sending user messages from the sender to the receiver

Any help is much appreciated!

+4
source share
3 answers

, , , . , Chromecast setTimeout - . - setTimeout no-op Chromecast script. , Chromecast, , , Chromecast , .

window._setTimeout = window.setTimeout;
window.setTimeout = function(a, b) {
    // disable setTimeout so chromecast won't kill us after 5 minutes...
};

, , _setTimeout.

, - , cast_receiver_framework.js ( Wn(a, b)) . Google.

, , , Xn(a), - , , Chromecast.

+1

4 , , . , . Android.

    MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);

    MediaInfo mediaInfo = new MediaInfo.Builder("https://some-inaudible-clip.mp3")
            .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
            .setContentType("audio/mpeg")
            .setMetadata(metadata)
            .build();

    RemoteMediaClient remoteMediaClient = castSession.getRemoteMediaClient();

    remoteMediaClient.load(mediaInfo, true);
0

You can send a custom namespace message from the recipient to the sender. This should keep the heartbeat alive. However, your use case is not directly supported by the Cast SDK, so you have to experiment with the solution.

-1
source

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


All Articles