Added error handling for both media and source elements.