How to Fix the App Unexpectedly Stopping
If the app stops while it is in the background or the screen is off, the problem is the device's battery optimizer turning off what it thinks is an unused app. The solution is simple, but depends on the device model. There is a dedicated site with detailed instructions on how to fix this issue on each device known to have this issue:
https://dontkillmyapp.com/ If the app is on and the music pauses seemingly out of nowhere, it is a different issue, most likely caused by other apps interrupting audio. For a solution to this issue see here.