Track time music was played on media player

Hi,

I like to track the usage of the media player in home assistant to restrict the time my kids play audiobooks.

The idea was to start a time when the box is playing and stop the time, once the music stops. Then occasionally check if the time is above a certain threshold and act on this.

Any idea how I could do this ? Maybe through a helper ?

Thanks