使用 javascript 控制嵌入式 Windows 媒体播放器
我嵌入了一些视频,如果单击链接,我需要显示这些视频。所以我想做的是单击一个链接,它将显示一个视频,用户可以按播放按钮。如果他们单击另一个链接,则先前的视频将停止并显示新的视频。我当前的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您对 DIV 元素进行寻址,而不是对 ID 为
Video1
的控件进行寻址;Your addressing the DIV element, not the control which has ID
Video1
;我认为应该是 stop 中的 'S' 是大写
而不是
I think it should be where 'S' in stop is capital
Instead of