如何将 Ruffle flash 播放器模拟器嵌入到 HTML 文件中?

问题描述 投票:0回答:3

我需要帮助在带有 ruffle 的 HTML 站点中实现 swf (https://ruffle.rs/),我将“AddType application/wasm .wasm”添加到 apache 中的 httpd.conf 中,这是我的代码但它没有显示在我的本地主机服务器上:

<html><head><script src="ruffle/ruffle.js"></script>
</head>
<body>
<script>
    window.RufflePlayer = window.RufflePlayer || {};
    window.addEventListener("load", (event) => {
        const ruffle = window.RufflePlayer.newest();
        const player = ruffle.createPlayer();
        const container = document.getElementById("container");
        container.appendChild(player);
        player.load("mig29.swf");
    });
</script>
<script src="ruffle/ruffle.js"></script>

</body>
</html

我也尝试过这段代码,也没有运气:

<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <title>WORKAROUND</title>

    <script>
        window.RufflePlayer = window.RufflePlayer || {};
        window.RufflePlayer.config = {
            "public_path": "ruffle/",
            "polyfills": ["static-content", "plugin-detect", "dynamic-content"]
        };
    </script>
    <script src="ruffle/ruffle.js"></script>

    <!-- Start workaround -->
    <script>
        const swfobject = {};
    </script>
    <script>
        Object.defineProperty(swfobject, "embedSWF", {
            value: function() {
                var ruffle = window.RufflePlayer.newest();
                var player = ruffle.create_player();
                var container = document.getElementById(arguments[1]);
                container.innerHTML = "";
                container.style.width = arguments[2] + "px";
                container.style.height = arguments[3] + "px";
                player.style.width = container.style.width;
                player.style.height = container.style.height;
                container.appendChild(player);
                player.stream_swf_url(arguments[0]);
            },
            writable: false,
            configurable: false
        });
    </script>
    <!-- End workaround - This code also works if placed before <swfobject.js> -->

    <script src="swfobject.js"></script>

</head>
<body>

<div id="file_div">Flash Player not detected!</div>
<script>
    swfobject.embedSWF("mig29.swf", "file_div", "550", "400", "8");
</script>

</body>
</html>

我问了他们的不和谐,但到目前为止还没有答案。如果有人更熟悉褶边请帮忙。

flash emulation ruffle
3个回答
8
投票

我最近发现了如何让它发挥作用。对

ruffle.createPlayer()
返回的玩家调用 .play 需要一个对象或至少需要一个对象。做
player.load({ url: '/path/to/swf.swf' })
会起作用

swfobject.embedSWF = function(url, cont, width, height){
    var ruffle = window.RufflePlayer.newest(),
        player = Object.assign(document.getElementById(cont).appendChild(ruffle.createPlayer()), {
            width: width,
            height: height,
            style: 'width: ' + width + 'px; height: ' + height + 'px',
        });
    
    player.load({ url: url });
}

完整代码:

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset='utf8'>
    </head>
    <body>
        <div id='ruffle'></div>
        <script src='https://e9x.github.io/ruffle-example/ruffle.js'></script>
        <script>
var swfobject = {};

swfobject.embedSWF = function(url, cont, width, height){
    var ruffle = window.RufflePlayer.newest(),
        player = Object.assign(document.getElementById(cont).appendChild(ruffle.createPlayer()), {
            width: width,
            height: height,
            style: 'width: ' + width + 'px; height: ' + height + 'px',
        });
    
    player.load({ url: url });
}

swfobject.embedSWF('https://e9x.github.io/ruffle-example/1on1soccer_24.swf', 'ruffle', 500, 500);
        </script>
    </body>
</html>

(将 github.io 链接替换为您自己的链接)


1
投票

您尚未为玩家创建

<div>

以下所有代码位于

<body>
</body>
之间:

<div id="container"> </div>

<script src="ruffle/ruffle.js"></script>
    <script>
        window.RufflePlayer = window.RufflePlayer || {};
        window.addEventListener("load", (event) => {
            const ruffle = window.RufflePlayer.newest();
            const player = ruffle.createPlayer();
            const container = document.getElementById("container"); 
            container.appendChild(player);
            player.load({
                url: "mig29.swf", 
                backgroundColor: "#000", 
             });
            player.style.width = "450px"; 
            player.style.height = "450px";
        });
    </script>

请记住将此行添加到您的

.htaccess
并上传:

AddType application/wasm .wasm wasm

并且,还要记住将整个荷叶边自托管地毯(6 个文件)上传到根目录。


0
投票

耀眼的goblrt

22)(eee 1oh 6r ruffle html doctype a na html anna 我喜欢吸你妈妈

© www.soinside.com 2019 - 2024. All rights reserved.