我正在开发使用WebTorrent(谷歌演员定制接收器应用https://webtorrent.io,https://github.com/feross/webtorrent)使用JavaScript(铬)SDK和谷歌演员发件人应用.
我的应用程序的想法是从Google Cast发送者向Google Cast接收器发送torrent id(类似磁铁URI magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d或HTTP/HTTPS URL到*.torrent文件https://webtorrent.io/torrents/sintel.torrent),并使用Google Cast接收器中的WebTorrent显示媒体(视频或音频)来自洪流.
请注意,torrent ID不是媒体文件的直接URL.
现在我正在使用Google Cast命名空间和messageBus来发送和接收torrent ID.
WebTorrent API提供了两种显示媒体的方法:
file.appendTo:https://webtorrent.io/docs#-file-appendto-rootelem-function-callback-err-elem-file.renderTo:https://webtorrent.io/docs#-file-renderto-elem-function-callback-err-elem-这是我的接收器的代码:
<html>
<head>
<script src="https://www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
<script src="https://cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js"></script>
</head>
<body>
<video autoplay id='media' />
<script>
window.mediaElement = document.getElementById('media');
window.mediaManager = new cast.receiver.MediaManager(window.mediaElement);
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
window.messageBus = window.castReceiverManager.getCastMessageBus('urn:x-cast:com.google.cast.sample.helloworld');
window.messageBus.onMessage = function(event) {
displayVideo(event.data);
// Inform all senders on the CastMessageBus of the incoming message event
// sender …Run Code Online (Sandbox Code Playgroud)