Player - app freeze after some time

I have app for radio player listening.
Radio plays and work well.

After listening some time, player stop playing and I need to click pause and play again to start. - in some cases I got error “app not responding”, and “runtime error”
I tested it and I think that problem for that is internet connection, because when I am at stable position on wifi or 4G network, it works ok, but if I listen it in car (when my phone change network resources from one to another every few kilometers) I get this problem. Also if I don’t have enough fast internet connection.
I will mention that screen of app is open all the time, there is no turning off of the mobile screen, other applications are not used, and battery safer is off.

Is there any way to detect when this happens, and that I give the app order to start playing again when it stops because of some reason?