写H5活动页的需要音频,图标旋转停止保持当时的旋转角度,这样视觉体验效果好;

之前写法是点击pause()就直接停止动画,后来发现了animation有个比较好的属性animation-play-state:runnimg/paused可以让图标保持当前旋转角度;

以下是相关代码,比较简单,大神可以过,像我一样的小白,可以共同学习;

注意:

1、我测试用的是chrome浏览器,chrome浏览器现在是限制了音频以及视频无法自动播放;

在chrome 浏览器中输入:chrome://flags,搜索“Autoplay policy”,默认为“Default”,

修改为 “No user gesture is required” 就可以了;此方法仅限谷歌浏览器,

2、在微信浏览器中打开也不会自动播放,目前我的解决办法是:监听微信的接口

//微信端自动播放音频
document.addEventListener("WeixinJSBridgeReady", function() {
audio.play();
}, false);

HTML

<div class="audio">
<audio id="audioTag" src="音频地址" autoplay="autoplay" controls="controls" loop='false' hidden="true">您的浏览器暂不支持audio</audio>
</div>

CSS

/* 音频 */
.audio {
position:absolute;top:60/50rem;right:60/50rem;z-index:99;width:70/50rem;height:70/50rem;background:url(images/music.png) top center no-repeat; background-size:100% 100%;
animation:turn 1s linear infinite running;
-webkit-animation:turn 1s linear infinite running;
}
.paused{
animation-play-state: paused;
-webkit-animation-play-state: paused;
}
/* 音频动画 */
@keyframes turn{
0%{transform:rotate(0)};
100%{transform:rotate(1turn)}
} @-webkit-keyframes turn{
0%{transform:-webkit-rotate(0)};
100%{transform:-webkit-rotate(1turn)}
}

JS

//音频自动播放
var audio = $('#audioTag').get(0);
var controlsPlay = $('.audio');
controlsPlay.click(function() {
//改变暂停/播放icon
if (audio.paused) {
audio.play();
$(this).removeClass('paused') } else {
audio.pause();
$(this).addClass('paused')
}
});

//微信端自动播放音频
document.addEventListener("WeixinJSBridgeReady", function() {
audio.play();
}, false);

***audio在ios中禁止了autoplay属性,无法自动播放 ,找了很久看到大多数使用touchstart事件触发play()事件

目前还是没有比较好的解决方案,我最后的解决方案是ios不自动播放通过touchstart触发,android自动播放

Complete!

audio小记的更多相关文章

  1. Cocos2d-x项目移植到WinRT/Win8小记

    Cocos2d-x项目移植到WinRT/Win8小记 作者: K.C. 日期: 11/17/2013 Date: 2013-11-17 23:33 Title: Cocos2d-x项目移植到WinRT ...

  2. Cocos2d-x项目移植到WP8小记

    Cocos2d-x项目移植到WP8小记 作者: K.C. 日期: 10/24/2013 Date: 2013-10-24 00:33 Title: Cocos2d-x项目移植到WP8小记 Tags: ...

  3. [原]Paste.deploy 与 WSGI, keystone 小记

    Paste.deploy 与 WSGI, keystone 小记 名词解释: Paste.deploy 是一个WSGI工具包,用于更方便的管理WSGI应用, 可以通过配置文件,将WSGI应用加载起来. ...

  4. html5 audio总结

    前言 html5中对音频,视频播放原生支持.最近做了一个音乐播放器,得益于快过年了,才能抽出一点时间来总结一下.总的来说,html5对audio的支持非常强大, 难怪flash要死.浏览器上装播放插件 ...

  5. 《HTML5》 Audio/Video全解

    一.标签解读 <audio> 标签属性 <audio id="media" src="http://www.abc.com/test.mp3" ...

  6. video/audio在ios/android上播放兼容

    1.audio自动播放 <audio src='xxx.mp3' autoplay></audio> 上面是audio标签autoplay属性是自动播放,但是在安卓部分浏览器和 ...

  7. audio 基本功能实现(audio停止播放,audio如何静音,audio音量控制等)

    audio最简单原始的播放.暂停.停止.静音.音量大小控制的功能,注意某些浏览器会有权限无法自动播放噢(video也会如此) <!doctype html> <html> &l ...

  8. h5自定义audio(问题及解决)

    h5活动需要插入音频,但又需要自定义样式,于是自己写咯 html <!-- cur表示当前时间 max表示总时长 input表示进度条 --> <span class='cur'&g ...

  9. Your app declares support for audio in the UIBackgroundModes key in your Info.plist 错误

    提交AppStore时候被拒绝 拒绝原因:Your app declares support for audio in the UIBackgroundModes key in your Info.p ...

随机推荐

  1. SpringBoot连接Redis (Sentinel模式&Cluster模式)

    一.引入pom <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

  2. RhaPHP 微信公众号管理系统

    框架网址https://www.rhaphp.com/ 开发手册网址:: https://www.kancloud.cn/langleigelang/rhaphp/588488 git 克隆,如果克隆 ...

  3. tip多文件上传(自找)

    HTMl代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  4. .NET 6学习笔记(2)——通过Worker Service创建Windows Service

    通过Visual Studio中的Windows Service模板,我么可以创建.NET Framework版本的Windows Service,网络上对此已有详细且丰富的各路教程.但在我们升级到. ...

  5. 报错———http://mybatis.org/dtd/mybatis-3-mapper.dtd 报红解决方案

    初次使用mybatis时,下面红线上的地址报红. 解决方法是:将http://mybatis.org/dtd/mybatis-3-mapper.dtd拷贝.添加到下面标记处.

  6. 活用Windows Server 2008系统的几种安全功能

    与传统操作系统相比,Win2008系统的安全防范功能更加强大,安全防护能力自然也是高人一等,我们只要在平时善于使用该系统新增的各项安全防范功能,完全可以实现更高级别的安全保护目的.现在,本文就为大家贡 ...

  7. 5分钟了解Redis的内部实现跳跃表(skiplist)

    跳跃表简介 跳跃表(skiplist)是一个有序的数据结构,它通过在每个节点维护不同层次指向后续节点的指针,以达到快速访问指定节点的目的.跳跃表在查找指定节点时,平均时间复杂度为,最坏时间复杂度为O( ...

  8. Redis的Unable to connect to Redis和java.io.IOException: 远程主机强迫关闭了一个现有的连接问题的解决

      学习项目xhr系统用到springboot + vue(https://github.com/lenve/vhr),文档中要求使用到RabbitMQ,但是从我搭建开发环境来看,是否配置Rabbit ...

  9. 学习SpringMVC必知必会(3)~springmvc的请求和响应

    一.处理器方法响应处理 ▷ Controller方法该怎么返回.Controller数据该怎么进行共享 返回void/ModelAndView/String 1.Controller方法返回void ...

  10. select、poll和epoll的区别

    操作系统在处理io的时候,主要有两个阶段: 等待数据传到io设备 io设备将数据复制到user space 我们一般将上述过程简化理解为: 等到数据传到kernel内核space kernel内核区域 ...