更改嵌入视频文件的对象参数值

时间:2013-08-27 19:52:37

标签: jquery object embed src

当我的用户点击链接时,我希望更改源参数以及在视频对象中嵌入param,而我似乎无法显示新视频。参数中加载的默认视频效果很好,只是不知道该怎么做才能加载新视频。这是我的脚本和HTML。

<div id="videoPlayerDiv" style="height: 350px; width: 350px;">
<div id="videoTable">
    <table>
        <tr>
            <td><b>Trading Videos</b></td>
        </tr>
        <tr>
            <td>--></td><td><a href="#" onclick="playVideo('tradingOverview');">Trading Overview</a></td>
        </tr>
        <tr>
            <td>--></td><td><a href="#" onclick="playVideo('multiAccount');">Multi-Account Trading Wizard</a></td>
        </tr>
        <tr>
            <td>--></td><td><a href="#" onclick="playVideo('globalUnlock');">Global Unlock</a></td>
        </tr>
    </table>
</div>
<div id="videoPlayer" style="display:none; height: 250px; width: 250px;">
    <object id="objViewer" width="250" height="250" type="video/x-ms-asf" data="Wildlife.wmv" classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">
        <param name="url" value="Wildlife.wmv">
        <param name="filename" VALUE="Wildlife.wmv">
        <PARAM name="autostart" VALUE="0">
        <param name="uiMode" value="full">
        <param name="autosize" value="1">
        <param name="playcount" value="1">
        <EMBED TYPE="application/x-mplayer2" src="Wildlife.wmv" NAME="MediaPlayer" id="wmvViewer" autostart="false"
            WIDTH="250" HEIGHT="250" ShowControls="1" ShowStatusBar="0" ShowDisplay="0"> 
        </EMBED>
    </OBJECT><br/>
    <a onclick="returnVideos();">Return to Videos</a>
</div>

后面是代码;

function playVideo(x){
$("#videoTable").attr("style","display:none;");
$("#videoPlayer").attr("style","display:block;");

var videoToPlay = x;
switch(videoToPlay){
    case 'tradingOverview':
        //alert(videoToPlay);
        var newElement = "Wildlife.wmv";
        $("#wmvViewer").attr('src', newElement);
    break;
    case 'multiAccount':
        //alert(videoToPlay);
        var newElement = "BabyBoyMainBackground.wmv";
        $("#wmvViewer").attr('src', newElement);
    break;
    case 'globalUnlock':        
        var newElement = "Panel_Mask.wmv";
        $('#objViewer').find('embed').attr('url', newElement);
        $('#objViewer').find('embed').attr('filename', newElement);
        $("#wmvViewer").attr('src', newElement);
        //alert(videoToPlay);
    break;
}
}
function returnVideos(){
$("#videoTable").attr("style","display:block;");
$("#videoPlayer").attr("style","display:none;");
}

基本上在switch语句中,取决于用户按下哪个视频来查看我想要更改以下参数;

将所有这些值更改为声明的新视频文件。以上不同的情况是我尝试的不同的东西,但没有任何效果。 任何帮助将不胜感激。 谢谢大家!

1 个答案:

答案 0 :(得分:1)

经过一些研究后,我发现最好的方法是在我的switch case中重建代码中的整个object元素,并将其添加到div成功的.html()属性中。

function playVideo(x){
    $("#videoTable").attr("style","display:none;");
    $("#videoPlayer").attr("style","display:block;");
    $("#videoPlayer").html("");

    var videoToPlay = x;
    switch(videoToPlay){
        case 'tradingOverview':
            //alert(videoToPlay);
            var newElement = "<object id='objViewer' width='250' height='250' type='video/x-ms-asf' data='Wildlife.wmv' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'><param name='url' value='Wildlife.wmv'><param name='filename' VALUE='Wildlife.wmv'><PARAM name='autostart' VALUE='0'><param name='uiMode' value='full'><param name='autosize' value='1'><param name='playcount' value='1'><EMBED TYPE='application/x-mplayer2' src='Wildlife.wmv' NAME='MediaPlayer' id='wmvViewer' autostart='false' WIDTH='250' HEIGHT='250' ShowControls='1' ShowStatusBar='0' ShowDisplay='0'></EMBED></OBJECT><br/><a onclick='returnVideos();'>Return to Videos</a>";
            $("#videoPlayer").html(newElement);
        break;
        case 'multiAccount':
            //alert(videoToPlay);
            var newElement = "<object id='objViewer' width='250' height='250' type='video/x-ms-asf' data='BabyBoyMainBackground.wmv' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'><param name='url' value='BabyBoyMainBackground.wmv'><param name='filename' VALUE='BabyBoyMainBackground.wmv'><PARAM name='autostart' VALUE='0'><param name='uiMode' value='full'><param name='autosize' value='1'><param name='playcount' value='1'><EMBED TYPE='application/x-mplayer2' src='BabyBoyMainBackground.wmv' NAME='MediaPlayer' id='wmvViewer' autostart='false' WIDTH='250' HEIGHT='250' ShowControls='1' ShowStatusBar='0' ShowDisplay='0'></EMBED></OBJECT><br/><a onclick='returnVideos();'>Return to Videos</a>";
            $("#videoPlayer").html(newElement);
        break;
        case 'globalUnlock':        
            var newElement = "<object id='objViewer' width='250' height='250' type='video/x-ms-asf' data='Panel_Mask.wmv' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'><param name='url' value='Panel_Mask.wmv'><param name='filename' VALUE='Panel_Mask.wmv'><PARAM name='autostart' VALUE='0'><param name='uiMode' value='full'><param name='autosize' value='1'><param name='playcount' value='1'><EMBED TYPE='application/x-mplayer2' src='Panel_Mask.wmv' NAME='MediaPlayer' id='wmvViewer' autostart='false' WIDTH='250' HEIGHT='250' ShowControls='1' ShowStatusBar='0' ShowDisplay='0'></EMBED></OBJECT><br/><a onclick='returnVideos();'>Return to Videos</a>";
            $("#videoPlayer").html(newElement);
            //alert(videoToPlay);
        break;
    }
}