【问题标题】:Pan audio in cordova (play only out of left / right headphone)在科尔多瓦平移音频(仅从左/右耳机播放)
【发布时间】:2017-03-22 03:03:09
【问题描述】:

在 Cordova/Phonegap/Ionic 中是否有任何用于向左或向右平移音频的库?理想情况下,我想要一个声音文件并从左或右耳机声道播放,但不能同时播放。

我查看了 cordova-media-plugin、cordova-native-audio、cordova-audioToggle 和 soundJS/createJS。其中,似乎只有 soundJS 和 createJS 能够控制耳机输出和平移,但它似乎不适用于 Cordova。也没有角/科尔多瓦的例子。

【问题讨论】:

    标签: android angularjs cordova audio cordova-plugins


    【解决方案1】:

    在 Android 6.0 上,以下脚本有效。它利用了 Web Audio API。我还没有在 iOS 上测试过它,但我感觉它可以在那里工作(如果没有,请发表评论)。

    您需要在根目录中有一个“omg.mp3”文件来进行测试。您还应该使用 Cordova 构建,而不必担心您可能会在浏览器中遇到 CORS 或 Same-domain 错误

    <!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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-25
      • 2019-06-03
      • 1970-01-01
      相关资源
      最近更新 更多