2017-01-04 32 views
0

我想在左,右或兩個通道中播放振盪器,並且爲了實現這一點,我使用Web Audio Api中的StereoPannerNode。 當我在Chrome上運行「離子發球」時,一切正常,但是當我在Android上測試代碼時(我安裝了人行橫道插件),聲音來自兩個通道(通道中較低的位置,我不想聲音播放) 。使用Web Audio Api,Ionic和Crosswalk播放左/右聲道中的振盪器

我也嘗試了合併和Splitter節點,結果相同:在Chrome上工作,在Android上不起作用。

我試着用Android 4.4.2使用華碩ZenFone和使用Android 6.0的華爲p8。

這是我如何創建我的音頻上下文和panner節點。

var contextClass = (window.AudioContext); 
var audioCtx = new contextClass(); 
var panNode = audioCtx.createStereoPanner(); 

我不知道如何解決這個問題,任何想法?

回答

0

在Android 6.0上,以下腳本可用。它利用了Web Audio API。我還沒有在iOS上測試過它,但我有一個很好的感覺,它會在那裏工作(請評論,如果沒有)。

你需要在你的根目錄下有一個「omg.mp3」文件來測試。您還應該使用Cordova構建,而不必擔心在瀏覽器中可能獲得的CORS或同一域錯誤

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
    <meta name="viewport" content="width=device-width"> 

    <title>StereoPannerNode example</title> 

    <link rel="stylesheet" href=""> 
    <!--[if lt IE 9]> 
     <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
    <![endif]--> 
    </head> 

    <body> 
    <h1>StereoPannerNode example</h1> 
    <audio controls> 
     <source src="omg.mp3" type="audio/mp3"> 
     <p>Browser too old to support HTML5 audio? How depressing!</p> 
    </audio> 
    <h2>Set stereo panning</h2> 
    <input class="panning-control" type="range" min="-1" max="1" step="0.1" value="0"> 
    <span class="panning-value">0</span> 

    </body> 
<script> 
var audioCtx = new (window.AudioContext || window.webkitAudioContext)(); 
var myAudio = document.querySelector('audio'); 

var panControl = document.querySelector('.panning-control'); 
var panValue = document.querySelector('.panning-value'); 


// Create a MediaElementAudioSourceNode 
// Feed the HTMLMediaElement into it 
var source = audioCtx.createMediaElementSource(myAudio); 

// Create a stereo panner 
var panNode = audioCtx.createStereoPanner(); 

// Event handler function to increase panning to the right and left 
// when the slider is moved 

panControl.oninput = function() { 
    panNode.pan.value = panControl.value; 
    panValue.innerHTML = panControl.value; 
} 

// connect the AudioBufferSourceNode to the gainNode 
// and the gainNode to the destination, so we can play the 
// music and adjust the panning using the controls 
source.connect(panNode); 
panNode.connect(audioCtx.destination); 
    </script> 
</html>