php - 手机和平板电脑检测
问题描述
在滑块显示 4 个视频中,当用户通过移动设备访问时,我需要将视频替换为图片
<div class="hero__player">
<div class="player">
<?php
$detect = new Mobile_Detect;
if ($detect->
isMobile()) {
$tr = '
<img src="/templates/assets/images/button_ground_test.jpg" style="width:100%;">
';
$poster = "[xfvalue_videopathimage]";
if ($poster == "/templates/assets/images/car.jpg") {
echo $ec;
} else if ($poster == "/templates/assets/images/health.jpg") {
echo $tr;
} else if ($poster == "/templates/assets/images/property.jpg") {
echo $ec;
} else if ($poster == "/templates/assets/images/travel.jpg") {
echo $tr;
}
} else {
echo '
<video class="player__video" height="506" muted="" playsinline="" poster="[xfvalue_videopathimage]" preload="auto" width="506">
<source src="[xfvalue_videopath]" type="video/mp4">
Your browser does not support the video tag.
</source>
</video>
';
}
?>
</img>
</div>
</div>
如何在此代码中包含移动检测?
解决方案
老实说:你的代码有点乱,到处都是错误。所以,我会重新开始。
首先确保您遵循mobiledetect的安装说明,这样您在使用时就不会出错。
然后尝试运行这段代码:
<?php
// Include and instantiate the class.
require_once('Mobile_Detect.php');
$detect = new Mobile_Detect;
// detect mobiles and tables
if ($detect->isMobile() && $detect->isTablet()) {
echo "I will be showing images.";
}
else {
echo "I will be showing videos.";
}
您应该首先让此代码工作。在计算机和移动设备上进行测试。只有在那之后,才需要担心实际显示图像和视频。
如果此代码给您带来任何问题,那么您可以将其放在注释中,最好是您遇到的完整的第一个错误。
我建议您在遇到问题时提出一个关于显示图像和视频的新问题。图片一个问题,视频另一个问题。我这么说的原因是一个问题应该是关于一件事:移动检测、显示图像或显示视频。不是一次全部三个。
推荐阅读
- c - 通过使用堆栈在 C 中的 Postfix 计算器中获取用户输入,
- azure - Azure Bot Framework 如何自动添加/更新 Facebook 频道页面 ID 和令牌
- php - 如何从表中获取数据,以日期为键和对应的数据?
- ruby - 冗余not_if?
- r - 从 sparklyr 编写一个与 spark_apply() 一起使用的函数
- r - 从 R 调用 python 函数并传递参数
- python - 是否有一种干净的方法可以将仅 Python 3 的功能添加到在 2.7 中使用其他功能的类?
- html - html 到 cshtml - 无法解释的页面移动
- xamarin - 如何在 xamarin 表单的顶部选项卡式页面上添加搜索选项卡?
- python - 第二高分