Google Cast:加载元数据错误并且不存在 Access-Control-Allow-Origin 标头
Posted
技术标签:
【中文标题】Google Cast:加载元数据错误并且不存在 Access-Control-Allow-Origin 标头【英文标题】:Google Cast: Load Metadata Error and No Access-Control-Allow-Origin header is present 【发布时间】:2014-10-03 19:35:26 【问题描述】:我尝试使用我的 android 应用投射流。 流来自我自己网络中的 Sat-Receiver。 我通过 http 链接访问流,例如:
http://192.168.188.23:8001/1:0:19:283D:3FB:1:C00000:0
当我在 VLC 中打开流时,我得到以下编解码器信息:
类型:视频/ 编解码器:H264 - MPEG-4 AVC (part10) (h264)
在我的应用中,我构建了这个 MediInfo:
private static MediaInfo buildMediaInfo(String title, String subTitle, String studio, String url, String imgUrl, String bigImageUrl, List<MediaTrack> tracks)
MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, subTitle);
movieMetadata.putString(MediaMetadata.KEY_TITLE, title);
movieMetadata.putString(MediaMetadata.KEY_STUDIO, studio);
return new MediaInfo.Builder(url)
.setStreamType(MediaInfo.STREAM_TYPE_LIVE)
.setContentType("video/mp4")
.setMetadata(movieMetadata)
.setMediaTracks(tracks)
.build();
来自我的 Chromecast 的错误日志:
Failed to load resource: the server responded with a status of 404 (Not Found) https://www.gstatic.com/eureka/player/undefined
[0.292s] [goog.net.WebSocket] Opening the WebSocket on ws://localhost:8008/v2/ipc cast_receiver.js:18
The page at 'https://www.gstatic.com/eureka/player/player.html?skin' was loaded over HTTPS, but ran insecure content from 'ws://localhost:8008/v2/ipc': this content should also be loaded over HTTPS. player.html:1
Connecting to a non-secure WebSocket server from a secure origin is deprecated. player.html:1
[0.428s] [goog.net.WebSocket] WebSocket opened on ws://localhost:8008/v2/ipc cast_receiver.js:18
Failed to load resource: the server responded with a status of 404 (Not Found) https://www.gstatic.com/eureka/player/undefined
The page at 'https://www.gstatic.com/eureka/player/player.html?skin' was loaded over HTTPS, but displayed insecure content from 'http://192.168.188.23:8001/1:0:19:283D:3FB:1:C00000:0:0:0:': this content should also be loaded over HTTPS. media_player.js:38
XMLHttpRequest cannot load http://192.168.188.23:8001/1:0:19:283D:3FB:1:C00000:0:0:0:. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.gstatic.com' is therefore not allowed access. player.html:1
[ 13.011s] [cast.receiver.MediaManager] Load metadata error cast_receiver.js:18
nb cast_receiver.js:18
kb.Yb cast_receiver.js:18
B.log cast_receiver.js:13
I cast_receiver.js:16
Z.ra cast_receiver.js:88
g.ra cast_receiver.js:53
Ib cast_receiver.js:23
Fb cast_receiver.js:24
(anonymous function) cast_receiver.js:21
e.onError player.js:53
K media_player.js:61
Ie.Ba media_player.js:117
R.yb media_player.js:67
pc media_player.js:34
h.dispatchEvent media_player.js:33
Hc media_player.js:39
Jc media_player.js:42
D.dh media_player.js:40
D.tf media_player.js:40
我无法更改流本身的某些内容。
这是我的代码中的问题还是我的 Sat-Receiver(流)的问题?当我的 Sat-Receiver 出现问题时是否有解决方案?
编辑:
解决CORS问题后新的错误日志:
Failed to load resource: the server responded with a status of 404 (Not Found) https://www.gstatic.com/eureka/player/undefined
[ 0.280s] [goog.net.WebSocket] Opening the WebSocket on ws://localhost:8008/v2/ipc cast_receiver.js:18
The page at 'https://www.gstatic.com/eureka/player/player.html?skin' was loaded over HTTPS, but ran insecure content from 'ws://localhost:8008/v2/ipc': this content should also be loaded over HTTPS.
player.html:1
Connecting to a non-secure WebSocket server from a secure origin is deprecated. player.html:1
[ 0.367s] [goog.net.WebSocket] WebSocket opened on ws://localhost:8008/v2/ipc cast_receiver.js:18
Failed to load resource: the server responded with a status of 404 (Not Found) https://www.gstatic.com/eureka/player/undefined
The page at 'https://www.gstatic.com/eureka/player/player.html?skin' was loaded over HTTPS, but displayed insecure content from 'http://192.168.188.32/teststream1.php': this content should also be loaded over HTTPS.
cast_receiver.js:55
[ 12.071s] [cast.receiver.MediaManager] Load metadata error cast_receiver.js:18
nb cast_receiver.js:18
kb.Yb cast_receiver.js:18
B.log cast_receiver.js:13
I cast_receiver.js:16
Z.ra cast_receiver.js:88
g.ra cast_receiver.js:53
Ib cast_receiver.js:23
Fb cast_receiver.js:24
(anonymous function) cast_receiver.js:21
编辑 2: 流中的标头如下所示(使用 php 捕获):
[0] => HTTP/1.0 200 OK
[1] => Date: Sat, 04 Oct 2014 18:38:23 GMT
[2] => Server: Apache/2.2.22 (Debian)
[3] => X-Powered-By: PHP/5.4.4-14+deb7u9
[4] => Connection: Close
[5] => Access-Control-Allow-Origin: *
[6] => Content-Type: video/mpeg
当我在 VLC 中打开流时,我得到以下编解码器信息:
类型:视频/ 编解码器:H264 - MPEG-4 AVC (part10) (h264)
Android 代码同上。
收件人:https://github.com/googlecast/Cast-Simple-Receiver/blob/master/receiver.html
编辑 3
使用自定义样式适配器和优化代码:
错误日志转换:
cast.receiver.logger.setLevelValue(cast.receiver.LoggerLevel.DEBUG);
undefined
[405.177s] [cast.receiver.IpcChannel] Received message: "data":"\"currentTime\":0,\"type\":\"LOAD\",\"media\":\"streamType\":\"BUFFERED\",\"duration\":0,\"contentType\":\"video\\/mpeg\",\"contentId\":\"http:\\/\\/192.168.188.32\\/teststream1.php\",\"metadata\":\"subtitle\":\"Auslandskorrespondenten berichten\",\"studio\":\"Das Erste HD\",\"title\":\"Weltspiegel\",\"metadataType\":1,\"requestId\":2,\"autoplay\":true","namespace":"urn:x-cast:com.google.cast.media","senderId":"229:de.resper.e2cast-22" cast_receiver.js:18
[405.187s] [cast.receiver.CastMessageBus] Dispatching CastMessageBus message cast_receiver.js:18
[405.193s] [cast.receiver.MediaManager] MediaManager message received cast_receiver.js:18
[405.198s] [cast.receiver.MediaManager] Dispatching MediaManager load event cast_receiver.js:18
[406.017s] [cast.receiver.IpcChannel] IPC message sent: "namespace":"urn:x-cast:com.google.cast.system","senderId":"SystemSender","data":"\"type\":\"setappstate\",\"statusText\":\"Now Casting: Weltspiegel\"" cast_receiver.js:18
[406.046s] [cast.receiver.MediaManager] Load - contentId: http://192.168.188.32/teststream1.php autoplay: true time: 0 cast_receiver.js:18
The page at 'https://www.gstatic.com/eureka/player/player.html?skin' was loaded over HTTPS, but displayed insecure content from 'http://192.168.188.32/teststream1.php': this content should also be loaded over HTTPS.
cast_receiver.js:55
[408.624s] [cast.receiver.MediaManager] Load metadata error cast_receiver.js:18nb cast_receiver.js:18kb.Yb cast_receiver.js:18B.log cast_receiver.js:13I cast_receiver.js:16Z.ra cast_receiver.js:88g.ra cast_receiver.js:53Ib cast_receiver.js:23Fb cast_receiver.js:24(anonymous function) cast_receiver.js:21
[409.519s] [cast.receiver.MediaManager] Sending error message to 229:de.resper.e2cast-22 cast_receiver.js:18
[409.523s] [cast.receiver.IpcChannel] IPC message sent: "namespace":"urn:x-cast:com.google.cast.media","senderId":"229:de.resper.e2cast-22","data":"\"requestId\":2,\"type\":\"LOAD_FAILED\"" cast_receiver.js:18
[410.301s] [cast.receiver.IpcChannel] IPC message sent: "namespace":"urn:x-cast:com.google.cast.system","senderId":"SystemSender","data":"\"type\":\"setappstate\",\"statusText\":\"Ready To Cast\"" cast_receiver.js:18
【问题讨论】:
【参考方案1】:我在您的帖子中没有看到任何问题,所以我不确定您到底在问什么;您提到的错误表明您遇到了 chromecast 所需的 CORS 问题(基于 W3C 要求),您无法从 Cast SDK 端解决此问题。
【讨论】:
我添加了上面的问题。所以我的应用程序或我的演员接收器没有问题吗?在我的 Android 设备上,我可以毫无问题地播放视频流。 CORS 是 chromecast 播放流媒体需要满足的要求,通常是从提供内容的服务器添加的。一旦通过了这一点,就可以查看是否存在其他问题,但到目前为止,您的第一个阻塞问题是修复 CORS 问题。如果您可以控制提供内容的服务器,则应该能够添加 CORS 标头 我能够将 CORS 添加到流中。现在我不再收到 CORS 错误,但加载元数据错误仍然存在... 你用的是什么接收器? 这个:github.com/googlecast/Cast-Simple-Receiver/blob/master/…以上是关于Google Cast:加载元数据错误并且不存在 Access-Control-Allow-Origin 标头的主要内容,如果未能解决你的问题,请参考以下文章
com.google.cast.DeviceManager 不再公开?
由于数据类型,无法查询从 Google 表格加载的 BigQuery 表
Google 地图 - 您应用的 AndroidManifest.xml 中的必需元数据标签不存在