如何使用jwplayer和laravel 5.1从youtube动态加载嵌入的视频?

时间:2015-08-06 16:30:49

标签: jwplayer laravel-5.1

我正在使用laravel框架,我正在尝试使用JwPlayer动态加载视频。我试着这样做

<script type="text/javascript" src="http://content.jwplatform.com/libraries/WQWJdvRx.js"></script> {{-- jwplayer url + key may mv to head or footer --}}
<div id="myElement" title="{{ $video->subtitle }}"></div>
<script>

    function myFunction(){
        var div1 = document.getElementById("myElement");
        var attr = div1.getAttribute("title");


        jwplayer("myElement").setup({

            file: "attr",
            width: 640,
            height: 360,
            title:"title goes here",
            stretching:"fill",
            skin:{
                name:"stormtrooper"
            }
        });
    }

我尝试使用javascript来获取实际上特定于视频的类名。变量attr然后我尝试使用attr变量作为我的文件路径。但它不起作用。任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

我明白了。在我听取了关于删除引用的建议后,我不得不删除它的parentesis和大括号的功能。一切顺利 所以它从这个

开始
<script type="text/javascript"  src="http://content.jwplatform.com/libraries/WQWJdvRx.js"></script> 
<div id="myElement" title="{{ $video->subtitle }}"></div>
<script>

function myFunction(){
    var div1 = document.getElementById("myElement");
    var attr = div1.getAttribute("title");


    jwplayer("myElement").setup({

        file: "attr",
        width: 640,
        height: 360,
        title:"title goes here",
        stretching:"fill",
        skin:{
            name:"stormtrooper"
        }
    });
}

到这个

<script type="text/javascript"  src="http://content.jwplatform.com/libraries/WQWJdvRx.js"></script> 
<div id="myElement" title="{{ $video->subtitle }}"></div>
<script>

    var div1 = document.getElementById("myElement");
    var attr = div1.getAttribute("title");

    jwplayer("myElement").setup({

        file: attr,
        width: 640,
        height: 360,
        title:"title goes here",
        stretching:"fill",
        skin:{
            name:"stormtrooper"
        }
    });