Merge mainLoop into media.