|
本模块封装了原生代码调节app系统媒体音量功能(备注:由于iOS系统的特有情况,调节音量会自动弹出系统的音量图标)。
点击进入模块详情
- <!DOCTYPE html>
- <html>
- <head>
- <title>Module Develop</title>
- <meta charset="utf-8">
- <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
- <style type="text/css">
- html,
- body {
- height: 100%
- }
- body {
- background-color: #fff;
- margin: 0;
- }
- #wrap {
- height: 100%;
- position: relative;
- }
- #header {
- padding-top: 20px;
- background-color: #5082c2;
- height: 44px;
- position: relative;
- }
- #header h1 {
- font-size: 20px;
- height: 44px;
- line-height: 44px;
- margin: 0em;
- color: #fff;
- margin-left: 100px;
- margin-right: 100px;
- text-align: center;
- }
- #main {
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-box-pack: center;
- }
- a.button {
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-box-pack: center;
- -webkit-box-align: center;
- height: 32px;
- margin: 8px;
- background-color: rgba(240, 240, 240, 1.0);
- border-color: rgba(220, 220, 220, 1.0);
- border-width: 2px;
- border-style: solid;
- }
- a.active {
- background-color: rgba(240, 240, 240, 0.7);
- }
- </style>
- </head>
- <body>
- <div id="wrap">
- <div id="main">
- <a class="button" tapmode="active" onclick="startPlay()">播放音乐</a>
- <a class="button" tapmode="active" onclick="initVolume()">初始化</a>
- <a class="button" tapmode="active" onclick="getVolume()">获取当前音量</a>
- <a class="button" tapmode="active" onclick="setVolume(0)">设置媒体音量0</a>
- <a class="button" tapmode="active" onclick="setVolume(10)">设置媒体音量10</a>
- <a class="button" tapmode="active" onclick="setVolume(50)">设置媒体音量50</a>
- <a class="button" tapmode="active" onclick="setVolume(80)">设置媒体音量80</a>
- <a class="button" tapmode="active" onclick="setVolume(100)">设置媒体音量100</a>
- <a class="button" tapmode="active" onclick="setSpeakerphoneOn()">扬声器与听筒切换</a>
- </div>
- </div>
- </body>
- <script type="text/javascript" src="../script/api.js"></script>
- <script>
- var demo;
- function initVolume() {
- demo.initVolume(function(ret, err) {
- alert(JSON.stringify(ret));
- });
- }
- function getVolume() {
- demo.getVolume(function(ret, err) {
- alert(JSON.stringify(ret));
- });
- }
- function setVolume(index) {
- demo.setVolume({
- volume: index
- }, function(ret, err) {
- alert(JSON.stringify(ret));
- });
- }
- function setSpeakerphoneOn() {
- demo.setSpeakerphoneOn(function(ret, err) {
- alert(JSON.stringify(ret));
- });
- }
- function startPlay() {
- api.startPlay({
- path: 'widget://res/shangxuege.mp3'
- }, function(ret, err) {});
- }
- function apiready() {
- demo = api.require('volume');
- if (!demo) {
- alert("请添加模块后编译");
- return;
- }
- }
- </script>
- </html>
复制代码
|
|