Setting a Sleep Timer

You can set iPhone to stop playing music or videos after a period of time.

Set a sleep timer: 

From the Home screen choose Clock > Timer, then flick to set the number of hours and minutes. Tap When Timer Ends and choose Sleep iPod, tap Set, then tap Start to start the timer.

When the timer ends, iPhone stops playing music or video, closes any other open application, and then locks itself.