Hi, I'm Bhavik. Welcome to JustAnswer. I'm reviewing your question now, and will reply back ASAP.
This problem can be because of software or hardware issues, Please try following methods one by one and see if this workaround works in your case :-
1. Drag the CD/DVD icon to the Trash, reboot the Mac and hold down the mouse button, or the “Eject” button on your keyboard.2. Launch Apple’s Disk Utility application, select the stuck CD/DVD and hit the “Eject” button.3. Using the Terminal, enter the following command: drutil eject
Let me know if this fix your problem.