The smartphone would use the built in microphone to create a recording of the song you play. The recording is then analyzed and can tell you the BPM of the music you played. Ideally this would happen in real-time, or easier to build would be to analyze the recordingat the end once it’s finished.
An extra function could be when e.g. you listen to a song and want to play along (or dance along) the app could automatically match the BPM and phase, lock in and then also send that information to wearables who lock in as well.