前言
我有自己的播放器和自己的原生音频引擎。最近我决定为其添加演员表功能。要将音频“流式传输”到自定义演员应用程序,我决定使用WebSocket
并在其上发送 float32 PCM,然后通过WebAudio API
. 因为自定义音频格式,我决定自己写cast.receiver.media.Player实现sample.MyPlayer
问题
一旦我打电话play
或pause
我com.google.android.gms.cast.RemoteMediaPlayer
得到
java.lang.IllegalStateException:没有当前媒体会话
在打电话之前我当然会com.google.android.gms.cast.RemoteMediaPlayer.load
和这里有趣的时刻。并且由于某种原因sample.MyPlayer
没有收到mediaSessionId
看起来这与 java 端的异常有关。但是我sample.MyPlayer.load
在 js 方面调用了。
我的应用程序的日志片段
cast_receiver.js:61 [ 21.034s] [cast.receiver.MediaManager] 加载收到的消息:{"requestId":2,"media":{ ... },"autoplay":false,"currentTime":0}
来自默认接收器样本的日志片段
cast_receiver.js:61 [ 30.243s] [cast.receiver.MediaManager] 加载收到的消息:{"type":"LOAD","requestId":2,"mediaSessionId":0,"customData":null,"media" :{ ... },"自动播放":true,"currentTime":0}
如您所见,我的自定义接收器中的有效负载缺少mediaSessionId
, type
,customData
键
这都是我发现的一个问题。
我的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 </div>
<div class="preview-mode-timer-countdown"></div>
<div class="preview-mode-timer-sec"> 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>
问题
- 我的方法总体上是正确的吗?
- 我在哪里可以找到cast.receiver.media.Player的任何参考实现?或任何建议如何正确实施?
- 有什么问题
java.lang.IllegalStateException: No current media session
?