RJ,
Here is what Apple says on the matter in their guide to Apple Music Analytics:
"Plays are recorded when a user initiates song playback in Apple Music for more than 30 seconds. We provide a wholistic view of all Plays, including Plays from Apple Music radio stations. (Apple Music radio stations are created when a user picks a song or an artist to generate a custom radio station, or from an Apple Music curated radio station.)"
They don't give specifics of how they would count cases like your example, where you restart after 40 seconds. However, you can be darn sure that they have measures in place to exclude anything that looks like gaming the system.