huangxiaojing 4 年之前
父节点
当前提交
ddc5bcd6d8
共有 2 个文件被更改,包括 25 次插入16 次删除
  1. 1 1
      screenIos/WXtrialInterface.html
  2. 24 15
      screenIos/pcm-player.js

+ 1 - 1
screenIos/WXtrialInterface.html

@@ -115,10 +115,10 @@
 	<script type="text/javascript" src="jquery-1.11.0.min.js"></script>
 	<!-- ffm软解 -->
 	<script type="text/javascript" src="helper.js"></script>
+	<script type="text/javascript" src="jquery-weui.min.js"></script>
 	<script type="text/javascript" src="pcm-player.js"></script>
 	<script type="text/javascript" src="webgl.js"></script>
 	<script type="text/javascript" src="https://cdn.bootcss.com/vConsole/3.2.0/vconsole.min.js"></script>
-	<script type="text/javascript" src="jquery-weui.min.js"></script>
 	<script type="text/javascript" src="WXdraw.js?id=105"></script>
 
 	<script>

+ 24 - 15
screenIos/pcm-player.js

@@ -2,7 +2,7 @@ function PCMPlayer(option) {
     this.init(option);
 }
 
-PCMPlayer.prototype.init = function(option) {
+PCMPlayer.prototype.init = function (option) {
     var defaults = {
         encoding: '16bitInt',
         channels: 1,
@@ -40,19 +40,28 @@ PCMPlayer.prototype.getTypedArray = function () {
     return typedArrays[this.option.encoding] ? typedArrays[this.option.encoding] : typedArrays['16bitInt'];
 };
 
-PCMPlayer.prototype.createContext = function() {
+PCMPlayer.prototype.createContext = function () {
     this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
-    this.gainNode = this.audioCtx.createGain();
-    this.gainNode.gain.value = 1;
-    this.gainNode.connect(this.audioCtx.destination);
-    this.startTime = this.audioCtx.currentTime;
+    $.alert({
+        title: '提示',
+        text: '开始使用云手机',
+        onOK: () => {
+            this.audioCtx.resume().then(() => {
+                this.gainNode = this.audioCtx.createGain();
+                this.gainNode.gain.value = 1;
+                this.gainNode.connect(this.audioCtx.destination);
+                this.startTime = this.audioCtx.currentTime;
+            })
+        }
+    });
+
 };
 
-PCMPlayer.prototype.isTypedArray = function(data) {
+PCMPlayer.prototype.isTypedArray = function (data) {
     return (data.byteLength && data.buffer && data.buffer.constructor == ArrayBuffer);
 };
 
-PCMPlayer.prototype.feed = function(data) {
+PCMPlayer.prototype.feed = function (data) {
     if (!this.isTypedArray(data)) return;
     data = this.getFormatedValue(data);
     var tmp = new Float32Array(this.samples.length + data.length);
@@ -61,7 +70,7 @@ PCMPlayer.prototype.feed = function(data) {
     this.samples = tmp;
 };
 
-PCMPlayer.prototype.getFormatedValue = function(data) {
+PCMPlayer.prototype.getFormatedValue = function (data) {
     var data = new this.typedArray(data.buffer),
         float32 = new Float32Array(data.length),
         i;
@@ -72,11 +81,11 @@ PCMPlayer.prototype.getFormatedValue = function(data) {
     return float32;
 };
 
-PCMPlayer.prototype.volume = function(volume) {
+PCMPlayer.prototype.volume = function (volume) {
     this.gainNode.gain.value = volume;
 };
 
-PCMPlayer.prototype.destroy = function() {
+PCMPlayer.prototype.destroy = function () {
     if (this.interval) {
         clearInterval(this.interval);
     }
@@ -85,7 +94,7 @@ PCMPlayer.prototype.destroy = function() {
     this.audioCtx = null;
 };
 
-PCMPlayer.prototype.flush = function() {
+PCMPlayer.prototype.flush = function () {
     if (!this.samples.length) return;
     var bufferSource = this.audioCtx.createBufferSource(),
         length = this.samples.length / this.option.channels,
@@ -104,16 +113,16 @@ PCMPlayer.prototype.flush = function() {
             audioData[i] = this.samples[offset];
             /* fadein */
             if (i < 50) {
-                audioData[i] =  (audioData[i] * i) / 50;
+                audioData[i] = (audioData[i] * i) / 50;
             }
             /* fadeout*/
             if (i >= (length - 51)) {
-                audioData[i] =  (audioData[i] * decrement--) / 50;
+                audioData[i] = (audioData[i] * decrement--) / 50;
             }
             offset += this.option.channels;
         }
     }
-    
+
     if (this.startTime < this.audioCtx.currentTime) {
         this.startTime = this.audioCtx.currentTime;
     }