android - 无法在 Android 上执行 'postMessage' 消息上的 'DOMWindow'

标签 android youtube youtube-api video.js

我们正在使用 video.jsyoutube plugin .

加载视频时,控制台显示错误。

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://www.youtube.com') does not match the recipient window's origin ('http://www.youtube.com').

我遵循了建议的解决方案 here并添加了 forceSSL:true,它解决了桌面问题,但我仍然在 android 设备上得到它。

videoJS 实例创建:

scope.player = videojs('vid3', { techOrder: ["youtube"], controls: true, preload: "auto", autoplay: false, 'forceSSL':true, 'forceHTML5':true, src: attributes.src})

最佳答案

我假设您正在 WebView 中加载页面。您使用哪种方法? 我建议你使用方法 loadDataWithBaseURL()通过 http://www.youtube.com 作为 baseUrl

如文档中所写:

loadDataWithBaseURL loads the given data into this WebView, using baseUrl as the base URL for the content. The base URL is used both to resolve relative URLs and when applying JavaScript's same origin policy.

关于android - 无法在 Android 上执行 'postMessage' 消息上的 'DOMWindow',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23375719/

相关文章:

Android WebView navigator.getCurrentPosition 问题

Android:将主机名解析为 IP 时出错

javascript - Youtube API - 如何使用自定义控件打开/关闭字幕、更改语言?

android - 获取response.body并转换为String时出错

android - Android Gradle错误

ffmpeg - 通过 ffmpeg 以高清分辨率录制和流式传输桌面到 Youtube

javascript - css 属性下的自定义值 - CSS

youtube - 如何使用 youtube API 获取 channel 信息

youtube - 使用 YouTube API 仅在 YouTube 上搜索音乐轨道

android - Ionic 应用程序在 Android 设备/模拟器上启动时崩溃