使用 Chromecast 加密狗,我们试图显示来自 android 的位图,该位图经常更改到接收器上。我们目前的做法是将图像转换为 Base64,然后将其作为 URL 提交。这可行,但速度很慢,而且似乎效率低下。在接收器上显示本地位图的最佳方式是什么?
相关Java代码:
Bitmap bitmap1 = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap1.compress(CompressFormat.JPEG, 85, baos);
String image = "data:image/jpeg;base64,"+Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
mMessageStream.loadMedia(image, mMetaData, true);
接收器.html:
<html>
<script src="https://www.gstatic.com/cast/js/receiver/1.0/cast_receiver.js">
</script>
<script type="text/javascript">
var receiver = new cast.receiver.Receiver(
'ACTUAL_APP_ID_HERE', [cast.receiver.RemoteMedia.NAMESPACE],
"",
3);
var remoteMedia = new cast.receiver.RemoteMedia();
remoteMedia.addChannelFactory(
receiver.createChannelFactory(cast.receiver.RemoteMedia.NAMESPACE));
receiver.start();
window.addEventListener('load', function() {
var elem = document.getElementById('vid');
remoteMedia.setMediaElement(elem);
});
</script>
<body>
<img id="vid" style="position:absolute;top:0;left:0;height:100%;width:100%" />
</body>
</html>