简体   繁体   English

使用jQuery加载HTML视频不再起作用

[英]Loading HTML Video With jQuery not working anymore

Here is the Development site: legiondesigns.com/pauls 这是开发站点: legiondesigns.com/pauls

And I also posted a previous question here Loading HTML Video With jQuery and that was working for a few days then it just stopped working. 我还在此处发布了一个先前的问题,即使用jQuery加载HTML视频 ,该问题已经工作了几天,然后才停止工作。 I am using WordPress 4.2.2 so I know that I have to use "wp_localize_script" which I have done. 我正在使用WordPress 4.2.2,所以我知道我必须使用“ wp_localize_script”。 Because when you inspect the video element in chrome you can see that it is proper loading in the correct path. 因为当您检查镀铬的视频元素时,您可以看到它在正确的路径中正确加载。 I can even right click the link in the inspection tool and click "open link in new window" and it opens the video and starts playing it. 我什至可以右键单击检查工具中的链接,然后单击“在新窗口中打开链接”,它会打开视频并开始播放。 So I know that the link is correct and the "wp_localize_script" is working properly. 因此,我知道链接是正确的,并且“ wp_localize_script”正常运行。 But nothing is showing up except the poster image for the video. 但是除了视频的海报图像外,什么都没有显示。

When Looking at the debug console in firefox I see the message: "Invalid URI. Load of media resource failed (3) . So firefox is saying that it failed to load my videos. When I switch from console back to "inspector" in developer tools and find the video elements. It is showing the correct location and I can also copy that and paste it into a new window and the video comes up and plays. So I don't even see why firefox is giving me that error. 在firefox中查看调试控制台时,我看到消息: “无效的URI。媒体资源加载失败(3) 。因此firefox表示无法加载我的视频。当我在开发人员中从控制台切换回“检查器”时工具并找到视频元素,它显示了正确的位置,我也可以将其复制并粘贴到新窗口中,然后视频就会播放,因此,我什至都看不到为什么Firefox会给我这个错误。

Here is my WordPress Localization PHP: 这是我的WordPress本地化PHP:

$site_parameters = array(
  'site_url' => get_site_url(),
  'theme_directory' => get_template_directory_uri()
);
wp_localize_script('custom-js', 'SiteParameters', $site_parameters );

Here is my jQuery: 这是我的jQuery:

var v = [];

v[0] = ["/library/videos/header.webm", "/library/videos/header.ogv",   "/library/videos/header.mp4"];
v[1] = ["/library/videos/mobHead.webm", "/library/videos/mobHead.ogv", "/library/videos/mobHead.mp4"];

var index = window.innerWidth <= 641 ? 1 : 0;

$('#webmvid').attr('src', SiteParameters.theme_directory + v[index][0]);
$('#oggvid').attr('src', SiteParameters.theme_directory + v[index][1]);
$('#mp4vid').attr('src', SiteParameters.theme_directory + v[index][2]);

And here is my HTML: 这是我的HTML:

<video autoplay="" loop="" poster="/library/images/vidPoster.jpg" id="bgvid">
  <source id="webmvid" src="" type="video/webm">
  <source id="oggvid" src="" type="video/ogg">
  <source id="mp4vid" src="" type="video/mp4">
</video>

Im pretty much stuck so any help is greatly appreciated. 我几乎被困住了,因此不胜感激。

Well after racking my brain I figured it out. 好了,我绞尽脑汁想通了。 Well somewhat. 好吧。 It only works if I have something already in the src="" part of the html so by setting my HTML to: 仅当我在html的src =“”部分中已有内容时才起作用,因此将HTML设置为:

<video autoplay="" loop="" poster="/library/images/vidPoster.jpg" id="bgvid">
  <source id="webmvid" src="temp" type="video/webm">
  <source id="oggvid" src="temp" type="video/ogg">
  <source id="mp4vid" src="temp" type="video/mp4">
</video>

Now it works. 现在可以了。 If I remove the temp from src="" then it does not work. 如果我从src =“”中删除该临时文件,则它将不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM