【问题标题】:Azure media player(AMP) not working on chrome if script file is saved locally如果脚本文件保存在本地,Azure 媒体播放器 (AMP) 无法在 chrome 上运行
【发布时间】:2016-06-18 09:52:07
【问题描述】:

我已在本地保存了示例 AMP 视频 http://amp.azure.net/libs/amp/latest/samples/dynamic_setsource.html 的源并尝试播放视频。它适用于 IE 和 Edge,但不适用于 chrome。如果我托管这个文件,它就可以工作。 你能帮我理解这里有什么问题吗? 您可以尝试在 IE 和 Chrome 中运行脚本以查看差异。

<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Skill Cloud</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="http://amp.azure.net/libs/amp/1.7.1/skins/amp-default/azuremediaplayer.min.css" rel="stylesheet">
    <script src="http://amp.azure.net/libs/amp/1.7.1/azuremediaplayer.min.js"></script>
</head>
<body>
    <h1>Skill Cloud</h1>
    <video id="azuremediaplayer" class="azuremediaplayer amp-default-skin amp-big-play-centered" tabindex="0"> </video>
    <script>
        var myOptions = {
            autoplay: true,
            controls: true,
            width: "100%",
            height: "auto",
            poster: ""
        };
        var myPlayer = amp("azuremediaplayer", myOptions);
        myPlayer.src([{ src: "http://amssamples.streaming.mediaservices.windows.net/91492735-c523-432b-ba01-faba6c2206a2/AzureMediaServicesPromo.ism/manifest", type: "application/vnd.ms-sstr+xml" }, ]);
    </script>
    <footer>
        <br />
        <p>© Microsoft Corporation 2016</p>
    </footer>
</body>
</html>

谢谢

【问题讨论】:

标签: azure-media-services


【解决方案1】:

当您在本地运行代码时,Chrome 会使用 file:// 协议打开您的 index.html。由于 Chrome 的安全政策,不允许加载本地资源,这就是阻止播放的原因。 (如果您查看 JavaScript 控制台,我敢打赌您会看到类似的错误。)

要解决此问题,您可以使用像 Visual Studio 或 WebMatrix 这样的 IDE,它会自动为您设置本地 Web 服务器,以便您可以使用 http://localhost:8000 或您喜欢的任何端口访问您的页面。

如果您不想使用 VS 或 WebMatrix,也可以使用 Python 的 Simple HTTP 服务器。希望这对编码有所帮助和快乐:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多