5 Replies Latest reply on Oct 20, 2017 12:40 AM by baraam03

    Cordova no sound on bluetooth speeaker

    baraam03

      Hello,

      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.

      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.

      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)

      Any Idea please?

        • 1. Re: Cordova no sound on bluetooth speeaker
          kerrishotts Adobe Employee

          What device(s) and OS version(s) have you tried testing on? Do all exhibit the problem, or just some? What kind of BT speakers have you tried using? Do they all exhibit the same problem?

          • 2. Re: Cordova no sound on bluetooth speeaker
            baraam03 Level 1

            thank you for your answer,

            it is almost for different devices and OS versions and different bluetooth speakers.

            I had this problem using an old version of cordova, I thought that this is the problem but right now I use the last version of cordova and tested for cordova-android 6.2.3 with ni success.

             

            my current configuration:

            - cordova 7.0.1

                  - android 6.2.3

            - test devices : samsung, Wiko lenny , Caterpillar S60

            - bluetooth: baladéo Speakers, different car's bluetooth speakers

            • 4. Re: Cordova no sound on bluetooth speeaker
              kerrishotts Adobe Employee

              How do you play the audio file? What code do you use?

              • 5. Re: Cordova no sound on bluetooth speeaker
                baraam03 Level 1

                I use the following code:

                 

                var AudioCtor = window.AudioContext || window.webkitAudioContext;

                context= new AudioCtor();

                document.currentAudioContext=context;

                 

                play=function(path)

                {

                    ////path = path_to_my_audio_file.aac

                    var request = new XMLHttpRequest();

                    document.AudioContextCurrentRequest=request;

                     request.open('GET', path, true);

                    request.responseType = 'arraybuffer';

                    request.onload =playAudioContextOnLoad;

                    request.onerror =playAudioContextOnError;

                    request.send();

                }

                 

                playAudioContextOnLoad=function()

                {

                    request=document.AudioContextCurrentRequest;

                    document.currentAudioContext.decodeAudioData(request.response,

                        playOnDecodeAudio,

                        playOnDecodeAudioFail);

                }

                 

                 

                playOnDecodeAudio=function(buffer)

                {

                     playBuffer(buffer,AudioContextCurrentCallBack);

                }

                 

                 

                playBuffer=function(buffer,callBackend)

                {

                    var source =  document.currentAudioContext.createBufferSource();

                    source.buffer = buffer;

                    source.connect( document.currentAudioContext.destination);

                    source.onended =document.playBufferonended;

                    source.start(0);

                }