Add onPreChangeMedia and improve refreshing