Hearing Sound from Firefox Using Bluetooth Headphones in FreeBSD

I’ve gotten myself Bluetooth Headphones and a USB Bluetooth dongles, and I want to hear sounds through my new headphones.

Since the headphones are a Bluetooth device, they should be discovered and paired. In the famous manual, FreeBSD Handbook , there are two sections in which to find instructions on Bluetooth and sound:

  • 33.5 Bluetooth – in chapter 33 – Advanced Networking.
    There is also a useful utility named bluetooth-config you can use to create or modify the files ‘/etc/bluetooth/hcsecd.conf.; and ‘/etc/bluetooth/hosts
  • 8.2.3. Setting up Bluetooth Sound Devices – in chapter 8 – Multimedia

Having configured Bluetooth and installed virtual_oss. All you have to do each time you want to listen through your Bluetooth headphones is to run the following commands replacing BT_ADDR by your device name:

  1. hccontrol -n ubt0hci create_onnection BT_ADDR
  2. virtual_oss -C 2 -c 2 -r 48000 -b 16 -s 768 -R /dev/null -P /dev/bluetooth/BT_ADDR -d dsp

Now, if you use VLC to listen to audio, all you have to do is select the ‘dsp’ output device. But, if you want to hear the sounds plyed by Firefox, you should have to add a module to PulseAudio. I haven’t found any Bluetooth modules I can install on my FreeBSD, but have found that module-sndio can do the job for me,, to add it, run the command:

pkg install pulseaudio-module-sndio

And add the following line to ‘/usr/local/etc/pulse/default.pa

load-module module-sndio device=snd/0

To start the service sndio at boot time, add the following line to ‘/etc/rc.conf‘:

sndiod_enable="YES"

To hear sounds from the Firefox browser, make sure PulseAudio stream it to ‘/snd/0‘ My display manager is XFCE4, and I use the plugin ‘xfce4-pulseaudio-plugin’ to view my output devices. In the following image, you can see that firefox sounds are streamed to that device:

Now, if everythiing is set correctly, but you cannot hear the sound, type the follwing shell command as a regular user:

pulseaudio --kill
Advertisement

Add A New Local IP Address in FreeBSD

Before you upload an internet site, you better test it on your local machine. To do that, you should allocate an IP address known as a loopback address that does not require a modem for access. If you’ve installed Apache Httpd server, you’ll probably get an HTML page that reads “It works” upon connecting to “http://localhost” or http://127.0.0.1” from the web browser. But what if you want to create another site? How to make your server recognize an IP?

In this post I will describe by example the process of adding a local IP.

Step 1: Associate an IP with a Domain Name

If you want to create a domain name such as ‘example.coq‘, add a line for it in /etc/hosts in the format:

<inet-addr>   <alias>

For example:

127.0.0.2               example.coq

Step 2: Attach the IP Address To a Network Interface

To make an address available to internet servers, attach it to a network interface.

A network interface is the identifier followed by colons at the beginning of blocks returned by the command ifconfigFor example:

In this block lo0 is an interface name.

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
    options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
    inet6 ::1 prefixlen 128 
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2 
    inet 127.0.0.1 netmask 0xff000000 

From the prefix ‘lo’ of the interface name, you can know it is a loopback interface.

You can attach an address, login as root, and run ifconfig like in the following example:

ifconfig lo0 127.0.0.2 netmask 255.255.255.255 alias

This will attach IP address 127.0.0.2 to the loopback interface ‘lo0’

You can make the operating system add it each type you start your computer, by adding the following line to /etc/rc.conf:

ifconfig_lo0_alias0="inet 127.0.0.2 netmask 255.255.255.255"

You can learn more about virtual hosts from the section ‘11.6 Virtual Hosts” of the FreeBSD Handbook

Step 3: Start a Listening Server

Now, you can start a server that will listen on your address. You can do it by adding a virtual host in apache httpd, create a server in ‘node.js’, etc.

If you’ve installed ‘Apache24’ from the ports, you can find documentation in '/usr/local/share/doc/apache24'. In addition, you can find documentation in the httpd site.

Written with StackEdit.