BlueWave Studio forum
Output „currently playing“ song info via serial? - Printable Version

+- BlueWave Studio forum (https://bluewavestudio.io/community)
+-- Forum: OpenAuto Pro (https://bluewavestudio.io/community/forumdisplay.php?fid=86)
+--- Forum: External applications (https://bluewavestudio.io/community/forumdisplay.php?fid=68)
+--- Thread: Output „currently playing“ song info via serial? (/showthread.php?tid=2935)



Output „currently playing“ song info via serial? - Ladermeister - 09-17-2021

I would like to show currently playing song in my instrument cluster.
Inalready have a working solution that accepts serial input.
Is it possible to pass „currently playing“ string to a file or read it out from somewhere?
It would be easy to pass that to serial then.


RE: Output „currently playing“ song info via serial? - Ladermeister - 10-26-2021

Any option to do so?


RE: Output „currently playing“ song info via serial? - Daniel_BlueWave - 10-26-2021

Currently we do not have that in the plans.


RE: Output „currently playing“ song info via serial? - Lucastud - 12-15-2021

Hello,
if the song you stream to your head unit is via bluetooth, it is handeled by Bluez on your Raspberry (used by Open auto).

In that case you can talk to Bluez with DBUS to get the info you need :
Quote:D-Bus (short for "Desktop Bus") is a message-oriented middleware mechanism that allows communication between multiple processes running concurrently on the same machine.

I used it for my head unit, here is my Bluetooth_utils.py code :
https://github.com/lucastu/Dashboard-python-can/blob/367c21576a4af3c41e2982b58fbfe8cf91d1fd33/Dashboard/Bluetooth_utils.py

It allows to get : title, artist, album, timing,  duration,  position.

Hope it helps

Lucas

EDIT : Wouah.... I haven't seen the date of the post...


RE: Output „currently playing“ song info via serial? - Ladermeister - 12-23-2021

That’s not a problem, still helps :-)
Thanks for pointing to the right direction! And thanks for your script, I will immediately have a look!

EDIT: After trying your script, I have two questions:
I do not yet have Bluez installed - will the installation of bluez interfere with my current setup of audio, or is it just a software "add-on" that I can safely install?
When starting your script, I get an error message regarding conversion of time:
  File "Bluetooth_utils.py", line 52

    seconds = f"{seconds:02d}"
                             ^
SyntaxError: invalid syntax

I can work around by removing the time displayed, but why do I get that error and you don't?


RE: Output „currently playing“ song info via serial? - Lucastud - 12-24-2021

Bluez should already be installed as it is used by Open Auto Pro. (I don't remember installing it ....)

To Check if Bluez is installed, try this command in a terminal, it will give you the version or an error if not installed :
bluetoothd -v

(https://askubuntu.com/questions/352283/how-do-i-check-the-bluez-version)

Does the other informations still display when you removed the code that block you ? (title, artist...)
To get the Playback position I used :

millis = adapter.get('Position')

and then format it 
This part seems to not work for you so if millis is not initialized seconds does not exist that where the error come from.

If the title, album.. does not work, try :
https://linuxtut.com/fr/30cb07454670450e3adf/
It's the code I started from. 

You can also use bluez documentation :
https://kernel.googlesource.com/pub/scm/bluetooth/bluez/+/5.43/doc/media-api.txt
and this bit of code that help me :
https://qiita.com/eggman/items/339a9c9b338634ac27a5


RE: Output „currently playing“ song info via serial? - Ladermeister - 12-27-2021

Thanks for the answer. It seems I was indeed wrong:

pi@raspberrypi:~ $ bluetoothd -v
5.50

My simplified script with the removed parts of code (same result if I call the script with python or python3):
pi@raspberrypi:~/skripte $ python Bluetooth_utils_simple.py
title: No title
artist: No artist
album: No album
title: No title
artist: No artist
album: No album
(...)

I tried to call your original code with python3 instead of python, now it looks better (but still does not show any result - currently a song is playing):

pi@raspberrypi:~/skripte $ python3 Bluetooth_utils.py
title: No title
artist: No artist
album: No album
timing: 00:00
duration: 00:00
position: 0
title: No title
artist: No artist
album: No album
timing: 00:00
duration: 00:00
position: 0
(...)

I narrowed it down, and it seems that in the Bluetooth_utils.py the if-statement in below code snippet about 'player0' is not fulfilled, and 'adapter' does also return 'None':

    def run(self):
        title, artist, album, timing_format, duration_format, in_track_postition = "No title", "No artist", "No album", "00:00", "00:00", "0"
        objects = self.manager.GetManagedObjects()
        for path, ifaces in objects.items():
            if 'player0' in path :
                adapter = ifaces.get(self.ADAPTER_INTERFACE)
                if adapter is not None:
                    track =  adapter.get('Track')
                    [...]



Then, I tried out your links:

(your first link)
pi@raspberrypi:~/skripte $ python BT_MediaPlayer.py 

show
Traceback (most recent call last):
  File "BT_MediaPlayer.py", line 37, in
    track =  adapter.get('Track')
AttributeError: 'NoneType' object has no attribute 'get'

pi@raspberrypi:~/skripte $ python BT_MediaPlayer.py 

next
Traceback (most recent call last):
  File "BT_MediaPlayer.py", line 33, in
    BT_Media_iface.Next()
NameError: name 'BT_Media_iface' is not defined


(your third link)
pi@raspberrypi:~/skripte $ hciconfig

hci0: Type: Primary  Bus: USB
BD Address: 00:1A:7D:DA:71:13  ACL MTU: 310:10  SCO MTU: 64:8
UP RUNNING PSCAN ISCAN 
RX bytes:1081454 acl:0 sco:0 events:33327 errors:0
TX bytes:13862 acl:0 sco:0 commands:1284 errors:0


pi@raspberrypi:~/skripte $ python get_adapter.py 

/org/bluez/hci0
00:1A:7D:DA:71:13

so it seems to me I have Bluez (version 5.50), the get_adapter.py-script also finds an adapter with the address as shown above, but I cannot control any playback with BT_MediaPlayer.py that I both copied from your links.

So does that mean that my audio from the phone is not streamed via that bluetooth adapter?

Setup is: OAP, compatible Bluetooth-USB-dongle, Carlinkit (Apple CarPlay), iPhone X and music playing from Spotify (wirelessly via CarPlay) on OAP. 
But as far as I understood the audio from the phone should still be streamed over bluetooth using the extra BT-USB-Dongle.

Now double checking this, it seems to me that the audio is being streamed over Wifi when using wireless CarPlay - that would explain why I do not have any success with your script...


So that brings me back to OpenAuto Pro and the need to get that "currently playing" information somewhere from OAP, as OAP has its built-in support for the Carlinkit dongle - nothing I can grab from standard raspberry side I think...

@Daniel from BlueWave Studio: any chance to make that information about currently playing song etc. available somewhere?


RE: Output „currently playing“ song info via serial? - Daniel_BlueWave - 12-27-2021

Yes, we are working on that.


RE: Output „currently playing“ song info via serial? - Ladermeister - 12-27-2021

Oh that is so great to hear!