如何实现自己的cast.receiver.media.Player

时间:2016-06-14 13:28:21

标签: android websocket google-cast android-cast-api

前言

我有自己的播放器拥有自己的原生音频引擎。最近我决定为它添加强制转换功能。要#'流'音频到自定义演员应用程序我决定使用WebSocket并在其上发送float32 PCM,然后通过WebAudio API播放。由于自定义音频格式,我决定编写自己的cast.receiver.media.Player实现sample.MyPlayer

问题

我在play上致电pausecom.google.android.gms.cast.RemoteMediaPlayer

  

java.lang.IllegalStateException:没有当前的媒体会话

在打电话之前我当然会com.google.android.gms.cast.RemoteMediaPlayer.load和有趣的时刻。由于某种原因,sample.MyPlayer没有收到mediaSessionId看起来这与java方面的异常有关。但我在js方面的sample.MyPlayer.load叫。

我的应用程序的日志片段

  

cast_receiver.js:61 [21.034s] [cast.receiver.MediaManager]加载消息   收到:{" requestId":2," media":{...}," autoplay":false," currentTime":0 }

来自default receiver sample

的日志片段
  

cast_receiver.js:61 [30.243s] [cast.receiver.MediaManager]加载收到的消息:{" type":" LOAD"," requestId" :2," mediaSessionId":0," customData":null," media":{...}," autoplay":true " currentTime的":0}

正如您所看到的,我的自定义接收器中的有效负载缺少mediaSessionIdtypecustomData

这就是我发现的一个问题。

我的player.html

<!DOCTYPE html>
<html>
<head>
  <title>Cast Reference Receiver</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="player.css" />
  <script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
  <script type="text/javascript" src="//www.gstatic.com/cast/sdk/libs/mediaplayer/1.0.0/media_player.js"></script>
  <script type="text/javascript" src="player.js"></script>
</head>
<body style="margin: 0">
    <div id="player" class="player">
        <div class="logo"></div>
        <div class="spinner"></div>
        <div class="watermark"></div>
        <div class="gradient"></div>
        <div class="overlay">
            <div class="media-info">
                <div class="media-artwork"></div>
                <div class="media-text">
                    <div class="media-title"></div>
                    <div class="media-subtitle"></div>
                </div>
            </div>
            <div class="preview-mode-info">
                <div class="preview-mode-artwork"></div>
                <div class="preview-mode-text">
                    <div class="preview-mode-timer">
                        <div class="preview-mode-timer-starts">Up next in&nbsp;</div>
                        <div class="preview-mode-timer-countdown"></div>
                        <div class="preview-mode-timer-sec">&nbsp;secs...</div>
                    </div>
                    <div class="preview-mode-title"></div>
                    <div class="preview-mode-subtitle"></div>
                </div>
            </div>
            <div class="controls">
                <span class="controls-play-pause"></span>
                <span class="controls-cur-time"></span>
                <span class="controls-total-time"></span>
                <div class="controls-progress">
                    <div class="controls-progress-inner progressBar"></div>
                    <div class="controls-progress-thumb"></div>
                </div>
            </div>
        </div>
    </div>
    <script>
      var mediaManager_ = new cast.receiver.MediaManager(new sample.MyPlayer(), [
            cast.receiver.media.Command.LOAD, 
            cast.receiver.media.Command.PLAY, 
            cast.receiver.media.Command.STOP, 
            cast.receiver.media.Command.GET_STATUS,
            cast.receiver.media.Command.PAUSE, 
            cast.receiver.media.Command.STREAM_VOLUME,
            cast.receiver.media.Command.QUEUE_NEXT,
            cast.receiver.media.Command.QUEUE_PREV
        ]);
      var receiverManager = cast.receiver.CastReceiverManager.getInstance();
      receiverManager.start();
    </script>
</body>
</html>

问题

  1. 我的做法一般是对的吗?
  2. 我在哪里可以找到cast.receiver.media.Player的任何参考实现?或任何建议如何正确实施?
  3. 问题是什么java.lang.IllegalStateException: No current media session

0 个答案:

没有答案