You can use the Clock app on your iPhone to stop music from playing after a preset amount of time, which is handy if you want to play music while you fall asleep. Watch our video tip to learn how.
Check It Out: How to Set a Timer for Music on Your iPhone
The timer not only stops the music, but stops whatever you are doing. If you are looking at the phone when the timer ends, it will stop everything and you will see the lock screen. The result is that all user interaction ends and you will have to unlock the phone to do anything.