科尔多瓦蓝牙音箱上没有声音 [英] cordova no sound on bluetooth speakers

查看:102
本文介绍了科尔多瓦蓝牙音箱上没有声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用android(和IOS)应用程序,该应用程序播放音频消息没有问题.我的问题如下: 如果移动设备已经连接到蓝牙(启用并连接了蓝牙),则启动我的应用程序并播放音频文件,在这种情况下,无论是电视电话还是蓝牙扬声器,我什么都听不到.

I am working on an android (and IOS) application, the application plays audio messages without problem. My problem is as follow: if the mobile is already connected to bluetooth (bluetooth enabled and connected), if then I launch my application and I play an audio file in this case I hear nothing neither on the telephine nor on the bluetooth speaker.

但是,如果我启动我的应用程序然后又激活了蓝牙,然后播放了音频文件,就没问题了,声音在我的蓝牙扬声器上可以很好地播放.

But, if I launch my application and then I activate the bluetooth,then play the audio file, there is no problem, the sound goes out well on my bluetooth speakers.

我现在使用的解决方案是,当我启动应用程序时,我完全禁用了蓝牙,然后在onDeviceready(使用插件cordova)上将其重新启动,它可以像这样正常工作,但作为解决方案并不理想,它是令用户非常烦恼的是,蓝牙断开并重新连接,尤其是当它是汽车的蓝牙时.

The solution I used for now is that when I launch my application I disable completely the bluetooth and then I restart it on the onDeviceready (using a plugin cordova) it works fin like that but it is not ideal as solution, it is very annoying for the users that the bluetooth disconnect and reconnect especially when it is the bluetooth of the car.

有人有同样的问题吗?您能帮我找到另一个解决方案吗?

Does anyone have the same problem and can you help me find another solution.

我使用的是最新版本的Cordova(7.0.1),android(6.2.3)... 我使用了plugova cordova-plugin-bluetoothle重新启动蓝牙(禁用该功能,然后在应用程序启动后启用)

I use the latest versions of Cordova (7.0.1), android (6.2.3) ... and I use the plugova cordova-plugin-bluetoothle to restart bluetooth (disable then enable after the launch of the application)

有什么想法吗?

推荐答案

在这里完全一样的问题!我正在开发使用Cordova(7.1.0)构建的适用于Android(6.4.0)和iOS(4.5.3)的音乐网络应用程序.我使用webaudio API播放声音.除了在这种特定情况下之外,一切在每个平台上都适用:

Exact same problem here! I'm working on a musical webapp for Android (6.4.0) and iOS (4.5.3) built with Cordova (7.1.0). I use the webaudio API to play sounds. Everything works great on every platforms except in this specific case:

如果在启动我的应用程序之前启用并连接了蓝牙,则所有声音都不会播放. 仅在Android上会发生此问题.在某些型号/类型的Android设备上,它可以工作,而在其他型号/设备上,则不能.例如:

If the bluetooth is enabled and connected before I launch my App there is no sounds at all playing. This problem occurs only on Android. On some model/type of Android devices it works, on some others it doesn't... Example:

  • 三星J3(Android v5.1.1)=没有声音播放
  • LENOVO TB2(Android v5.1.1)=没有声音播放
  • HUAWEI VTR(Android v7.0)=没有声音播放
  • LG G6(Android v7.0)=像魅惑一样工作!

不幸的是,我还没有找到任何干净"的解决方案.我做的和你的一样(BT =蓝牙):

Unfortunately I didn't find any 'clean' solutions yet. I do the same than yours (BT=bluetooth):

  1. 如果已连接,则强制禁用BT,
  2. 重新加载整个页面,
  3. 重新连接BT.

我在测试期间发现的唯一提示是有关AudioContext对象的属性. AudioContext对象具有名为 baseLatency 的属性. 官方DOC 尚不清楚:

The only hint I found during my tests is about an attribute into the AudioContext object. The AudioContext object has a attribute called baseLatency. The official DOC isn't really clear about it:

这表示AudioContext将音频从AudioDestinationNode传递到音频子系统所引起的处理延迟秒数[...]

This represents the number of seconds of processing latency incurred by the AudioContext passing the audio from the AudioDestinationNode to the audio subsystem [...]

我了解到的是,此属性使您可以估计(以秒为单位)AudioContext将声音传送到目的地所需的时间/延迟...

What I understood is that this property give you an estimation (in seconds) of the time/delay needed by AudioContext to bring a sound to his destination...

在代码中初始化AudioContext之后,您可以请求以下 baseLatency (只读属性):

Right after the AudioContext has been initialized in your code, you can ask for this baseLatency (read-only property):

var context = new AudioContext();
console.log(context.baseLatency);// 0.008 for example

我在测试中注意到的是,每次出现问题时,此baseLatency总是始终大于0.2.

What I noticed during my tests, is that this baseLatency is always higher than 0.2 everytime the problem occurs.

带有蓝牙已禁用的示例:

// baseLatency on computer = 0.008
// baseLatency on iOS devices = 0.05
// baseLatency on Android devices = 0.05

带有蓝牙已启用的示例:

// baseLatency on computer = 0.008 (same)
// baseLatency on iOS devices = 0.05 (same)
// baseLatency on (some) Android devices = 0.2 (HIGHER)

好吧,我做了数百次测试,每次都得到相同的结果.如果在某些 Android设备上启动应用程序之前启用了BT,则 baseLatency 将高于0.2,这意味着AudioContext将无法在您的应用程序中播放任何声音.我知道这不是一个解决方案,但是可以通过让您确定该应用程序是否可以播放声音来帮上忙.

Well, I did this test hundreds times, each times the same result. If BT is enabled before you launch the App on some Androids devices, the baseLatency will be higher than 0.2 meaning the AudioContext won't be able to play any sounds in your app. This is not a solution I know, but that can helps a little by letting you know for sure if the App will play sounds or not.

我试图重新初始化AudioContext对象,但这根本不起作用...即使重建了AudioContext对象,baseLatency也保持不变.

I tried to re-initialize the AudioContext object, but this doesn't works at all... the baseLatency stay the same even if you reconstruct the AudioContext object.

我希望这个微小的提示可以帮助我们找到解决方案!

I hope this tiny hint could help us to find a solution!

这篇关于科尔多瓦蓝牙音箱上没有声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆