@yoda/bluetooth. BluetoothPlayer

new BluetoothPlayer()

Use bluetooth.getPlayer() instead of this constructor.

Extends

Methods

start(name, subsequent, cb) → {null}

Starts the bluetooth player, it starts the a2dp-sink, and waits for the connection from a peer.

You should listens the following events:

  • opened when the a2dp-sink is opened.
  • closed when the a2dp-sink is closed.
  • stateupdate when any of states updates.
  • error when something went wrong from bluetooth service.
Parameters:
Name Type Description
name string

the bluetooth name.

subsequent string

the subsequent command.

cb function
Fires:
Returns:
Type:
Null
Example
var player = require('@yoda/bluetooth').getPlayer()
player.on('opened', () => {
  console.log('bluetooth has been opened')
})
player.start('YodaOS Bluetooth')

end() → {null}

End the bluetooth player.

Returns:
Type:
Null

suspend()

Suspend the Bluetooth player, this pauses the current audio stream on bluetooth service util resume() gets called. This commonly is used when the device is awaken, system needs the bluetooth player suspends, and listenning the user.

resume()

Resume from the suspend state.

play() → {null}

Play the music.

Returns:
Type:
Null

stop() → {null}

Stop the music.

Returns:
Type:
Null

pause() → {null}

Pause the music.

Returns:
Type:
Null

next() → {null}

Play next music.

Returns:
Type:
Null

prev() → {null}

Play previous music.

Returns:
Type:
Null

disconnectPeer()

Disconnect from device

disconnect()

Disconnect the event socket, this is deprecated please use .destroyConnection() instead.

destroyConnection()

Destroy the connection to bluetooth service, this firstly sends the OFF command and destroy the connection.

Events

opened

When the volume needs to be changed from bluetooth service.

opened

When the bluetooth(a2dp) is opened.

closed

When the bluetooth(a2dp) is closed.

stateupdate

When play state updates.

Properties:
Name Type Description
a2dpstate string

the a2dp state

connect_state string

if the connect

connect_name string

the connected device name

play_state string

the state of playing on the peer device

Type:

error

When something is wrong.

Type: