To use the iPhone's sleep timer, set a time in the Clock app's timer, and set the When Timer Ends option to Stop Playing.