added a state machine, and a play last stream method