use a function to play sound, remove duplicate codes