Android Question Set audio path to BT device(Solved)

Discussion in 'Android Questions' started by Nizze, Apr 5, 2016.

  1. Nizze

    Nizze Active Member Licensed User

    Hi

    After searching the forum wihtout finding my ansver .

    How can i set sound ??
    I want to play sound in BT device and not in my phone .

    But i cant find info on how to do that

    i recive a audio stream like this :
    Code:
    audioStream.Initialize("AudioStream"8000True16, audioStream.VOLUME_MUSIC)
    Then it will "play" in the phones speaker.
    How do i get it in my paired BT device ?

    Br
    Nizze
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    The audio routing should be handled automatically by the OS.

    Does it play the music through the Bluetooth device is you play it with MediaPlayer (play a different file)?
     
  3. Nizze

    Nizze Active Member Licensed User

    Hi Erel
    The BT device works only with audio when i use Phone , not with any Media Player .
    The device is a SAVOX BTR-155 . It is a BT mic/speaker with PTT function

    I found the ptt function, and it works .
    Code:
    Sub Serial1_Connected (Success As Boolean)
       
        
    If Success Then
            
    ToastMessageShow("Ptt Button connected "False)
            TestStream.Initialize(Serial1.InputStream,Serial1.OutputStream,
    "TestStream")
        
    End If
       
    End Sub

    Sub teststream_NewData (Buffer() As Byte)
        
    Dim msg As String
        msg = 
    BytesToString(Buffer, 0, Buffer.Length, "UTF8")
       
        
    Select Case msg
           
            
    Case "+PTT=P" 'Ptt button pressed
                PTT_ON
            
    Case "+PTT=R" 'Ptt button relesed
                PTT_OFF   
           
        
    End Select
       
        
    'ToastMessageShow(msg, False)
    End Sub
    So i need to turn on this audio path like phone does
    Is there anything in Phone i can use ?


    // Nizze
     
    Last edited: Apr 6, 2016
  4. Nizze

    Nizze Active Member Licensed User

    Done some mor tests ..
    But no Luck so far

    Code:
    Sub StartBluetoothSco()
      
    Dim r As Reflector
      
    ToastMessageShow("Start sco"False)

      r.Target = r.GetContext
      r.Target = r.RunMethod2(
    "getSystemService""audio""java.lang.String")
      r.RunMethod(
    "startBluetoothSco")
      
    Log("StartBluetoothSco"'<--------------
    End Sub
    And in Manifest added:

    Code:
    AddPermission(android.permission.BLUETOOTH)
    AddPermission(android.permission.BLUETOOTH_ADMIN)
    AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)
    Update this code .

    It works !
     
    Last edited: Apr 7, 2016
  5. Erel

    Erel Administrator Staff Member Licensed User

  6. Nizze

    Nizze Active Member Licensed User

    Hi Erel
    I had a typo in the code above , The code works.

    The PTT function is serial and is working

    Thanks !
     
    PeterPaulGumpal likes this.
  7. PeterPaulGumpal

    PeterPaulGumpal Member Licensed User

    Thanks Nizze :) Just spent the whole day yesterday around several codes but this one only worked for me:

    Sub StartBluetoothSco()
    Dim r As Reflector
    ToastMessageShow("Start sco", False)

    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
    r.RunMethod("startBluetoothSco")
    Log("StartBluetoothSco") '<--------------
    End Sub



    except that I had to add these:
    (Service_Create)
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS


    (Activity_Resume)
    r.RunMethod("startBluetoothSco")


    as the control of the bluetooth key (from the headset) gets overridden by Google Now after the first click (meaning I used the headset's physical button to trigger transfer of audio to the headset).
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice