使用 javascript 控制嵌入式 Windows 媒体播放器

发布于 2024-12-06 15:30:37 字数 2462 浏览 2 评论 0原文

我嵌入了一些视频,如果单击链接,我需要显示这些视频。所以我想做的是单击一个链接,它将显示一个视频,用户可以按播放按钮。如果他们单击另一个链接,则先前的视频将停止并显示新的视频。我当前的 HTML 结构是:

<div>
    <ul>
        <li><a onclick="ShowVideo(0);" href="javascript:void(0);" class="CalltrackLink">Missed Opportunities</a></li>
        <li><a onclick="ShowVideo(1);" href="javascript:void(0);" class="CalltrackLink">Create User</a></li>
    </ul>
</div>
<div>
    <div id="Video1Div" style="display:none">
        <OBJECT id="Video1" width="640" height="480" 
        STANDBY="Loading Windows Media Player components..." 
        CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
        type="application/x-oleobject">

            <PARAM NAME="URL" VALUE="Video1.mp4" />
            <PARAM NAME="SendPlayStateChangeEvents" VALUE="True" />
            <PARAM NAME="AutoStart" VALUE="False" />
            <PARAM NAME="ShowControls" value="True" />

        </OBJECT>
    </div>
    <div id="Video2Div" style="display:none">
        <OBJECT id="Video2" width="640" height="480" 
        STANDBY="Loading Windows Media Player components..." 
        CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
        type="application/x-oleobject">

            <PARAM NAME="URL" VALUE="Video2.mp4" />
            <PARAM NAME="SendPlayStateChangeEvents" VALUE="True" />
            <PARAM NAME="AutoStart" VALUE="False" />
            <PARAM NAME="ShowControls" value="True" />

        </OBJECT>
    </div>
</div>

我有以下 javascript,这是我从互联网上的各种来源获得的:

function ShowCalltrack(i) {
    $('#Video1Div').hide();
    $('#Video2Div').hide();

    document.getElementById("Video1Div").controls.stop();    
    document.getElementById("Video2Div").controls.stop();

    if(i == 0)
    {
        $('#Video1Div').show();
    }
    else if(i == 1)
    {
        $('#Video2Div').show();
    }
}

当我运行它时,我收到错误:

无法获取属性“stop”的值:对象为 null 或未定义

如果我删除有问题的代码,那么当用户单击另一个链接时,上一个视频仍将播放,并且如果用户没有这样做,您可以听到音频手动停止视频。

我可以使用此代码停止上一个视频:

var Video1 = document.getElementById("Video1Div");
var Video1Text = Video1.innerHTML;
Video1.innerHTML = '';
Video1.innerHTML = Video1Text;

这确实会阻止视频播放,但是,问题是,如果您返回到之前打开的链接,视频将从停止的位置恢复与以前一样,我需要从头开始。

有什么想法吗?

I have embeded a few videos which I need to display if a link is clicked. so what I am trying to do is click a link and it will display a video, which the user can press play on. If they click another link, the previous video stops and a new video will be displayed. The current HTML structure I have is:

<div>
    <ul>
        <li><a onclick="ShowVideo(0);" href="javascript:void(0);" class="CalltrackLink">Missed Opportunities</a></li>
        <li><a onclick="ShowVideo(1);" href="javascript:void(0);" class="CalltrackLink">Create User</a></li>
    </ul>
</div>
<div>
    <div id="Video1Div" style="display:none">
        <OBJECT id="Video1" width="640" height="480" 
        STANDBY="Loading Windows Media Player components..." 
        CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
        type="application/x-oleobject">

            <PARAM NAME="URL" VALUE="Video1.mp4" />
            <PARAM NAME="SendPlayStateChangeEvents" VALUE="True" />
            <PARAM NAME="AutoStart" VALUE="False" />
            <PARAM NAME="ShowControls" value="True" />

        </OBJECT>
    </div>
    <div id="Video2Div" style="display:none">
        <OBJECT id="Video2" width="640" height="480" 
        STANDBY="Loading Windows Media Player components..." 
        CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
        type="application/x-oleobject">

            <PARAM NAME="URL" VALUE="Video2.mp4" />
            <PARAM NAME="SendPlayStateChangeEvents" VALUE="True" />
            <PARAM NAME="AutoStart" VALUE="False" />
            <PARAM NAME="ShowControls" value="True" />

        </OBJECT>
    </div>
</div>

I have the following javascript which I got from various sources on the internet:

function ShowCalltrack(i) {
    $('#Video1Div').hide();
    $('#Video2Div').hide();

    document.getElementById("Video1Div").controls.stop();    
    document.getElementById("Video2Div").controls.stop();

    if(i == 0)
    {
        $('#Video1Div').show();
    }
    else if(i == 1)
    {
        $('#Video2Div').show();
    }
}

When I run this I get the error:

Unable to get value of the property 'stop': object is null or undefined

If I remove the offending code then, when the user clicks another link the previous video will still be playing, and you can hear the audio, if the user did not manually stop the video.

I was able to stop the previous video by using this code:

var Video1 = document.getElementById("Video1Div");
var Video1Text = Video1.innerHTML;
Video1.innerHTML = '';
Video1.innerHTML = Video1Text;

this does stop the video from playing, however, the problem with this is, if you go back to a link which you had previously opened the video will resume from where it left off with previously, and I need to to start again from the start.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泛泛之交 2024-12-13 15:30:37

您对 DIV 元素进行寻址,而不是对 ID 为 Video1 的控件进行寻址;

var Wmp = document.getElementById("Video1");
if (Wmp.controls.isAvailable('Stop'))
   Wmp.controls.stop();

Your addressing the DIV element, not the control which has ID Video1;

var Wmp = document.getElementById("Video1");
if (Wmp.controls.isAvailable('Stop'))
   Wmp.controls.stop();
谈下烟灰 2024-12-13 15:30:37

我认为应该是 stop 中的 'S' 是大写

document.getElementById("Video1Div").Stop();

而不是

document.getElementById("Video1Div").controls.stop();

I think it should be where 'S' in stop is capital

document.getElementById("Video1Div").Stop();

Instead of

document.getElementById("Video1Div").controls.stop();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文